我制作动画并让它永远运行。现在我想在点击一个按钮后停止它。然后动画将按钮的图像从 0 度旋转到 360 度。我想停止动画,但让动画完成当前循环。例如,如果按钮旋转了 200 度,并且我单击了停止按钮,我希望动画仍然运行到 360 度然后停止。动画代码如下:
CABasicAnimation *anim2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
anim2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
anim2.fromValue = [NSNumber numberWithFloat:0];
anim2.toValue = [NSNumber numberWithFloat:-((360*M_PI)/180)];
anim2.repeatCount = HUGE_VALF;
anim2.duration = 10;
[self.imgBtn.layer addAnimation:anim2 forKey:@"transform"];
谢谢!