我们如何将图像从起点移动到终点360度? 移动图像360度?
答案 0 :(得分:1)
您可以按一定数量的弧度旋转视图,无论它是小于完整旋转还是完整旋转的多倍,而不必将旋转分割成碎片。作为示例,以下代码将每秒一次旋转视图达指定的秒数。您可以轻松地修改它以按一定数量的旋转或某些弧度旋转视图。
- (void) runSpinAnimationWithDuration:(CGFloat) duration;
{
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];
rotationAnimation.duration = duration;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 1.0;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[myView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
答案 1 :(得分:1)
任何轴上的360度旋转都会使视图保持不变。所以不要触摸图像,你很高兴!
答案 2 :(得分:0)
您也可以使用动画功能(CAValueFunction):
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
rotationAnimation.duration = duration;
rotationAnimation.fromValue = [NSNumber numberWithFloat:0.0];
rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2.0];
rotationAnimation.valueFunction = [CAValueFunction functionWithName:kCAValueFunctionRotateZ];
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[myView.layer addAnimation:rotationAnimation forKey:nil];