如何将图像从起点360度移动到终点?360度移动图像?
发布于 2009-10-06 05:55:55
可以按一定数量的弧度旋转视图,而不必将旋转拆分为多个部分,而不管它是小于完全旋转还是完全旋转的倍数。例如,下面的代码将每秒旋转视图一次,持续指定的秒数。您可以轻松地对其进行修改,以按一定数量的旋转或按一定数量的弧度旋转视图。
- (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"];
}发布于 2009-10-06 06:09:51
在任意轴上旋转360度会使视图保持不变。所以不要碰图像,你就可以走了!
发布于 2011-03-17 06:47:33
您也可以使用动画函数(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];https://stackoverflow.com/questions/1523803
复制相似问题