1

我正在使用以下 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"];
  }
4

1 回答 1

5

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

因此,如果您想让一个动画总共运行 80 秒,您需要计算一次动画的持续时间——可能是这一层的一次完整旋转——然后将持续时间设置为该值。然后让动画重复几次完整的旋转以填写您的持续时间。

所以是这样的:

rotationAnimation.repeatCount = 8.0;

或者,您可以使用 repeatDuration 来实现类似的效果:

rotationAnimation.repeatDuration = 80.0;

In either case, you need to set the duration to the time of a single spin, and then repeat it using ONE of these methods. If you set both properties, the behavior is undefined. You can check out the documentation on CAMediaTiming here.

于 2011-07-19T21:49:52.670 回答