1

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

有什么建议么?谢谢你。

4

2 回答 2

2

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

[rotationAnimation setRemovedOnCompletion:NO];
于 2011-01-10T02:48:23.447 回答
2

您正在添加动画,但并未修改实际的底层属性。创建动画后,只需将图层的transform属性设置为包含相同的最终结果。

于 2011-01-10T02:55:32.197 回答