我开发了一个应用程序,它需要车轮绕z轴旋转,随着时间的推移逐渐增加或降低车轮速度。我使用CABasicAnimation &我的代码如下。虽然我在特定的时间间隔更改了层的速度属性,但会导致车轮产生“干扰”效应。在旋转车轮时改变CALayer在CABasicAnimation中的速度引起混乱效应
/* ** */
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.toValue = [NSNumber numberWithFloat:-2*M_PI];
animation.duration = 4.0f;
animation.repeatCount = INFINITY;
[animation setValue:@"left" forKey:@"side"];
[animation setDelegate:self];
animation.removedOnCompletion=NO;
animation.fillMode = kCAFillModeForwards;
animation.cumulative = YES;
imageLeft.layer.beginTime = CACurrentMediaTime();
/************/
在定时器予改变的ImageView的CALayer的速度如下,其中dPlayedPercentage是一个变量。
imageLeft.layer.speed=1.0+dPlayedPercentage;
[imageLeft.layer addAnimation:animation forKey:@"SpinAnimation"];
我认为这是由于位置复位而改变的CALayer的速度性能。我应该怎样做才能纠正这一点。或者有任何其他方式来做这个动画?
添加以下代码已整流的加加速度在动画中。 imageLeft.layer.timeOffset = [imageLeft.layer convertTime:CACurrentMediaTime()fromLayer:nil]; \t imageLeft.layer.beginTime = CACurrentMediaTime(); \t imageLeft.layer.speed = 1.0 + dPlayedPercentage; – Augus