我有一个可以使用CABasicAnimation旋转的using图像。当我得到一个指南针更新时,我会通过时间偏移来更改/更新图像的起始点。
这很好用,但当我从指南针获得更新并删除旧动画时,它会跳回开始位置,然后再移动到新的开始位置。这会导致闪烁效果。有没有办法同时删除和添加动画,或者以某种方式防止这种情况发生?
到目前为止,我的代码如下。
[self.waveImage.layer RemoveAllAnimations];
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.fromValue = [NSNumber numberWithFloat:0.0];
animation.toValue = [NSNumber numberWithFloat:2.0 * M_PI];
animation.duration = 1.0;
animation.repeatCount = HUGE_VALF; // Repeat forever
animation.speed = 1.0/duration;
animation.timeOffset = startingPhase;
animation.fillMode = kCAFillModeForwards;
[self.waveImageView.layer addAnimation:animation forKey:@"transform.rotation.z"];发布于 2012-05-11 22:02:34
发布于 2012-05-13 20:37:19
尝尝这个。
卸下timePhase。您希望从头开始设置新更改的动画。timePhase将使其移动您的动画。
不要使用重复计数。这将导致动画从开始到结束,然后捕捉回来并重复。
add animation.removedOnCompletion = NO.
https://stackoverflow.com/questions/10552801
复制相似问题