首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能再翻转层,CALayer,CATransform3DRotate。

不能再翻转层,CALayer,CATransform3DRotate。
EN

Stack Overflow用户
提问于 2013-04-09 04:09:42
回答 1查看 551关注 0票数 0

我想做的是:

  1. 单击一个botton进行垂直翻转。
  2. 再点击一个按钮,图层会把它翻回来,等等……

守则如下:

代码语言:javascript
复制
    @interface ViewController (){
        CALayer *plane;
    }
    @end

    @implementation ViewController

    -(void)viewDidLoad
    {
        [super viewDidLoad];

        [self addALayer];


    }
    - (void)addALayer{


        plane                   =   [CALayer layer];
        plane.backgroundColor   =   [[UIColor orangeColor] CGColor];
        //[plane insertSublayer:normalBackground atIndex:0];

        plane.opacity           =   1;
        plane.frame             =   CGRectMake(0, 0, 300, 100);
        plane.position          =   CGPointMake(250, 150);
        plane.anchorPoint       =   CGPointMake(0.5, 0.5);
        plane.borderColor       =   [UIColor whiteColor].CGColor;
        plane.borderWidth       =   3;
        plane.cornerRadius      =   10;
        [self.view.layer addSublayer:plane];

    }
- (IBAction)click:(id)sender {
        BOOL isClicked                  =   ((UIButton*)sender).selected;
        ((UIButton*)sender).selected    =   !((UIButton*)sender).selected;
        CATransform3D transfrom         =   CATransform3DIdentity;
        transfrom.m34                   =   -1.0/ 500;
        if ( !isClicked ) 
            transfrom                   =   CATransform3DRotate(transfrom, degToRad(180.0), 1, 0, 0);
        else 
            transfrom                   =   CATransform3DRotate(transfrom, degToRad(-180.0), 1, 0, 0);

        plane.transform                 =   transfrom;
    }

然而,在第一步,我可以看到图层翻转180度,当我再次点击按钮,没有发生任何事情。

我是不是在中间漏掉了什么?请帮帮忙。

EN

回答 1

Stack Overflow用户

发布于 2013-04-09 04:36:10

下面的代码只获取发送方的选定状态。州只设一次。检查下面修改的代码。

代码语言:javascript
复制
// Have a global variable
 BOOL isClicked 

- (IBAction)click:(id)sender {
        CATransform3D transfrom         =   CATransform3DIdentity;
        transfrom.m34                   =   -1.0/ 500;
        if ( !isClicked ) {
            transfrom                   =   CATransform3DRotate(transfrom, degToRad(180.0), 1, 0, 0);
        isClicked                       =   true;
        }
        else{ 
            transfrom                   =   CATransform3DRotate(transfrom, degToRad(360.0), 1, 0, 0); // OR CAN ALSO BE 0
        isClicked                       =   false;
        }
        plane.transform                 =   transfrom;
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15893144

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档