开发者

how to speed up CABasicAnimation?

开发者 https://www.devze.com 2023-03-21 04:39 出处:网络
I am using the following CABasicAnimation. But, its very slow..is there a way to speed it up ? Thanks.

I am using the following CABasicAnimation. But, its very slow..is there a way to speed it up ? Thanks.

- (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 degre开发者_运维问答ss, 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"];
  }


Core Animation animations can repeat a number of times, by setting the repeatCount property on the animation.

So if you'd like to have an animation run for a total 80 seconds, you need to figure out a duration for one pass of the animation – maybe one full spin of this layer – and then set the duration to be that value. Then let the animation repeat that full spin several times to fill out your duration.

So something like this:

rotationAnimation.repeatCount = 8.0;

Alternatively, you can use repeatDuration to achieve a similar affect:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消