Cocoa 如何使CALayer在其最终位置永久旋转?

Cocoa 如何使CALayer在其最终位置永久旋转?,cocoa,calayer,caanimation,cabasicanimation,Cocoa,Calayer,Caanimation,Cabasicanimation,我正在尝试将CALayer旋转到特定角度,但是,一旦动画完成,层将跳回到其原始位置。如何正确旋转图层,使其保持在最终目的地 这是我正在使用的代码 CABasicAnimation *rotationAnimation =[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; //Rotate about z-axis [rotationAnimation setFromValue:[NSNumber numberWithF

我正在尝试将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];

有什么建议吗?谢谢。

好的,我通过将removeOnCompletion设置为NO来修复它

[rotationAnimation setRemovedOnCompletion:NO];

好的,我通过将removeOnCompletion设置为NO来修复它

[rotationAnimation setRemovedOnCompletion:NO];

您正在添加动画,但没有修改实际的基础属性。创建动画后,只需将层的
变换
属性设置为包含相同的最终结果。

您正在添加动画,但没有修改实际的基础属性。创建动画后,只需将层的
变换
属性设置为包含相同的最终结果。

匿名编辑器说:“这不是正确答案。正确的方法是将层的变换属性设置为动画的最终值。”(来自编辑评论;我投票反对,因为这应该是一个评论;我对他们是否正确没有意见)rotationAnimation.fillMode=kCAFillModeForwards;works to一位匿名编辑说:“这不是正确的答案。使最终值‘保持不变’的正确方法是将层的变换属性设置为动画的最终值。”(来自编辑评论;我投票拒绝,因为它应该是注释;我对它们是否正确没有意见)rotationAnimation.fillMode=kCAFillModeForwards;也有效