How to permanently leave a CALayer rotated at its final location?
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.
精彩评论