如何将旋转的 CALayer 永久保留在其最终位置?
我试图将 CALayer 旋转到特定角度,但是,一旦动画完成,图层就会跳回其原始位置。如何正确旋转图层以使其保持在最终目的地?
这是我正在使用的代码
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];
有什么建议吗?谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我通过将removeOnCompletion 设置为NO 来修复它。
Ok I fixed it by setting removeOnCompletion to NO.
您正在添加动画,但没有修改实际的基础属性。创建动画后,只需设置图层的
transform
属性即可包含相同的最终结果。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.