使用此代码我正在尝试旋转图像。图像旋转但速度相同。 我试图旋转平滑旋转的图像,但我不能这样做。这是我的代码:
(void)spinLayer:(CALayer *)inLayer duration:(CFTimeInterval)inDuration
direction:(int)direction repeat:(int)repeat
{
repeatcount = repeat+repeatcount;
timer = [NSTimer scheduledTimerWithTimeInterval: inDuration target: self selector:@selector(setCountLableValue) userInfo: nil repeats: YES];
CABasicAnimation* rotationAnimation;
rotationAnimation =
[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.fromValue = [NSNumber numberWithFloat: M_PI *2.0 * direction];
rotationAnimation.repeatCount = repeat;
NSLog(@"Repeat count %d",repeat);
rotationAnimation.duration = inDuration;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[inLayer addAnimation:rotationAnimation forKey:@"rotation"];
}
答案 0 :(得分:1)
您可以使用不同的timingFunction。您使用线性函数,尝试其中一个而不是kCAMediaTimingFunctionLinear
NSString * const kCAMediaTimingFunctionEaseIn;
NSString * const kCAMediaTimingFunctionEaseOut;
NSString * const kCAMediaTimingFunctionEaseInEaseOut;
关于重复问题,请在创建动画后尝试添加以下代码:(这只是一个想法,我真的不知道为什么缓动函数只使用一次)
rotationAnimation.removedOnCompleted = NO;
rotationAnimation.fillMode = kCAFillModeForwards;
rotationAnimation.cumulative = YES;