ios - 如何加快CABasicAnimation?

标签 ios cabasicanimation

我正在使用以下CABasicAnimation。但是,它非常慢..有没有办法加快它?谢谢。

- (void)spinLayer:(CALayer *)inLayer duration:(CFTimeInterval)inDuration
 direction:(int)direction
{
CABasicAnimation* rotationAnimation;

// Rotate about the z axis
 rotationAnimation = 
[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

// Rotate 360 degress, in direction specified
 rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 * direction];

// Perform the rotation over this many seconds  
rotationAnimation.duration = inDuration;

// Set the pacing of the animation
rotationAnimation.timingFunction = 
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

// Add animation to the layer and make it so
[inLayer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
  }

最佳答案

通过在动画上设置repeatCount属性,Core Animation动画可以重复多次。

因此,如果您希望动画播放一共80秒,则需要计算动画通过一遍的持续时间-可能是该层的一整圈-然后将持续时间设置为该值。然后,让动画重复几次完整旋转,以填满您的播放时间。

所以像这样:

rotationAnimation.repeatCount = 8.0;

另外,您可以使用repeatDuration实现类似的效果:
rotationAnimation.repeatDuration = 80.0;

无论哪种情况,您都需要将持续时间设置为一次旋转的时间,然后使用以下方法之一重复该持续时间。如果同时设置两个属性,则行为是不确定的。您可以在CAMediaTiming here上查看文档。

关于ios - 如何加快CABasicAnimation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6751126/

相关文章:

ios - 如何在 animationDidStop 中识别 CAShapeLayer

ios - 将子图层的路径更改为另一路径时创建动画

ios - 如何在 iOS 中获得完美的旋转 UIView 的 X,Y 位置

swift - 什么时候使用UIView动画,CABasicAnimation和UIViewPropertyAnimator?

ios - 分支 clicked_branch_link 为 0 没有元数据 Swift

ios - 识别不是 NSContentSizeLayoutConstraint 或类似的高度/宽度约束

ios - 导航 Controller 未加载(push,present)另一个viewController

ios - 如何在 Sprite Kit、Objective C 中用手指移动来击打物体

ios - 从`xcode'停止应用程序后,应用程序无法正常工作。

ios - 按下主页按钮时 CABasicAnimation 消失