开发者

How to permanently leave a CALayer rotated at its final location?

开发者 https://www.devze.com 2023-02-04 09:30 出处:网络
I am trying to rotate a CALayer to a specific angle ho开发者_如何转开发wever, once the animation is done, the layer jumps back to its original position. How would I rotate the layer properly so that i

I am trying to rotate a CALayer to a specific angle ho开发者_如何转开发wever, once the animation is done, the layer jumps back to its original position. How would I rotate the layer properly so that it stays at its final destination?

Here is the code that I am using

CABasicAnimation *rotationAnimation =[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; //Rotate about z-axis
[rotationAnimation setFromValue:[NSNumber numberWithFloat:fromDegree]];
[rotationAnimation setToValue:[NSNumber numberWithFloat:toDegree]];
[rotationAnimation setDuration:0.2];
[rotationAnimation setRemovedOnCompletion:YES];
[rotationAnimation setFillMode:kCAFillModeForwards];

Any suggestions? Thank you.


Ok I fixed it by setting removeOnCompletion to NO.

[rotationAnimation setRemovedOnCompletion:NO];


You're adding an animation, but you aren't modifying the actual underlying property. After you create the animation, just set the layer's transform property to contain the same final result.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号