我开发了一个应用程序,该应用程序需要一个轮子围绕 z 轴旋转,并随着时间的推移稳定地增加或减少轮子的速度。我使用 CABasicAnimation & 我的代码如下。当我以特定的间隔更改图层的速度属性时,它会导致车轮产生“Jerk”效果。
/ * ** * /
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();
/************/
在计时器中,我如下改变图像视图的 CALayer 的速度,其中 dPlayedPercentage 是一个变量。
imageLeft.layer.speed=1.0+dPlayedPercentage;
[imageLeft.layer addAnimation:animation forKey:@"SpinAnimation"];
我认为这是由于更改 CALayer 的速度属性时位置重置所致。我应该怎么做才能纠正这个问题。或者任何其他方式来做这个动画?