简体   繁体   English

如何转换(旋转)已存在的CALayer /动画?

[英]How to transform (rotate) a already exist CALayer/animation?

I have added a CALayer to the UIView of my app: 我在我的应用程序的UIView中添加了一个CALayer:

    CATransition *animation = [CATransition animation];
    [animation setDelegate:self];
    [animation setDuration:0.35];
    [animation setTimingFunction:UIViewAnimationCurveEaseInOut];
        animation.type = @"pageCurl";
        animation.fillMode = kCAFillModeForwards;
        animation.endProgress = 0.58;
    [animation setRemovedOnCompletion:NO];
    [[self.view layer] addAnimation:animation forKey:@"pageCurlAnimation"];

Now when the user rotates the device, the layer always stays in the same position on the screen (in line to the homescreen button). 现在,当用户旋转设备时,图层始终保持在屏幕上的相同位置(与主屏幕按钮对齐)。 Is it possible to rotate the animation/layer? 是否可以旋转动画/图层? I tried 我试过了

self.view.layer.transform = CGAffineTransformMakeRotation (angle);

but this code just rotates the UIView and not the animation/layer I set. 但是这段代码只是旋转UIView而不是我设置的动画/图层。

The error is because the type of the transform property of CALayer is CATransform3D, and you're giving it a CGAffineTransform. 错误是因为CALayer的transform属性的类型是CATransform3D,并且你给它一个CGAffineTransform。 Use CATransform3D CATransform3DMakeRotation (CGFloat angle, CGFloat x, CGFloat y, CGFloat z); 使用CATransform3D CATransform3DMakeRotation(CGFloat角度,CGFloat x,CGFloat y,CGFloat z); instead. 代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM