我将旋转的toValue设置为2 * PI,但为什么在动画后这些视图不是水平的?

时间:2017-11-16 11:27:16

标签: ios objective-c core-animation

代码如下:

CABasicAnimation *rotateWhenBoom = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotateWhenBoom.fromValue = @0;
rotateWhenBoom.toValue = @(M_PI*2.0);
rotateWhenBoom.duration = 0.3f;
rotateWhenBoom.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];

CAAnimationGroup *boom = [CAAnimationGroup animation];
boom.animations = @[[self moveOutWithBtn:btn], rotateWhenBoom];
boom.fillMode = kCAFillModeForwards;
boom.removedOnCompletion = NO;

效果: effect

在动画之前,视图都是水平的。我为这些视图添加了旋转动画,旋转的toValue为2 * PI。为什么在动画之后它们不是水平的? 在此先感谢!!

1 个答案:

答案 0 :(得分:0)

你的最后两行代码: boom.fillMode = kCAFillModeForwards; boom.removedOnCompletion = NO;

表示图层保持最终动画状态,并且动画在完成时不会自动从图层中删除。您可能想要删除最后一行boom.removeOnCompletion = NO

CALayer和CAAnimation的一个很好的指南解释了这一点:https://www.objc.io/issues/12-animations/animations-explained/