我使用以下代码在圆形路径中旋转对象:
CGRect boundingRect = CGRectMake(-25, -25, 50, 50);
orbit = [CAKeyframeAnimation animation];
orbit.keyPath = @"position";
orbit.path = CFAutorelease(CGPathCreateWithEllipseInRect(boundingRect, NULL));
orbit.duration = 4;
orbit.additive = YES;
orbit.repeatCount = HUGE_VALF;
orbit.calculationMode = kCAAnimationPaced;
orbit.rotationMode = kCAAnimationRotateAuto;
orbit.speed = speed;
[_imageView.layer addAnimation:orbit forKey:@"orbit"];
现在,我想控制旋转物体暂停,恢复,向相反方向旋转等。我找到了暂停和恢复的方法。但有没有什么方法可以将对象旋转到与恢复后相反的方向。
我尝试通过将动画移除到图层并再次添加动画来向相反方向旋转。但在这种情况下,物体走出圆形并到达中心。当我再次添加动画时,它会转到圆形路径并开始旋转。
当物体在圆形路径中旋转时,有没有办法改变旋转方向?
以下代码用于暂停:
CFTimeInterval pausedTime = [_imageView.layer convertTime:CACurrentMediaTime() fromLayer:nil];
_imageView.layer.speed = 0.0;
_imageView.layer.timeOffset = pausedTime;
以下代码用于恢复:
CFTimeInterval pausedTime = [layer timeOffset];
layer.speed = 1.0;
layer.timeOffset = 0.0;
layer.beginTime = 0.0;
CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
layer.beginTime = timeSincePause;