How to permanently leave a CALayer rotated at its final location?
-
09-10-2019 - |
Question
I am trying to rotate a CALayer to a specific angle however, 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.
Solution
Ok I fixed it by setting removeOnCompletion to NO.
[rotationAnimation setRemovedOnCompletion:NO];
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow