[英]Spin UIImageView 360 Degrees using UIView animations?
我只是试图顺时针旋转UIImageView 360度:
#define DEGREES_TO_RADIANS(angle) (angle / 180.0 * M_PI)
和这个
imageView.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(360));
但是,即使调用它们,imageView也根本不会旋转。 我在做什么不对劲? 我不想使用CAAnimations所以请不要建议我这样做。
谢谢!
问题是Core Animation将通过查找从当前状态到新状态的最直接路由来应用动画。 旋转0度与360度旋转相同,因此最终转换的最直接路径是绝对不做任何事情。
180度的两个步骤将是有问题的,因为有两个同样直接的路线,从0到180度,核心动画可以选择。 所以你可能需要将动画分成三个步骤。 首先使用UIViewAnimationOptionCurveEaseIn
,第二个使用UIViewAnimationOptionCurveLinear
,最后使用UIViewAnimationOptionCurveEaseOut
。
也许是因为变换不是在一段时间内发生的。 在我看来,只要它不能随着时间的推移而感知,你可能需要在一段时间内执行变换或变换序列。
以下是Tommy的答案启发的代码。
我用了
NSInteger step;
跟踪图像视图的当前旋转度。
- (void)startAnimation
{
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationOptionCurveLinear
animations:^{
imageView.transform = CGAffineTransformMakeRotation(120 * step / 180.0f * M_PI);
}
completion:^(BOOL finished) {
step++;
// rotation completed, reset for the next round
if (step == 4){
step = 1;
}
// perform the next rotation animation
[self startAnimation];
}];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.