[英]iPhone UIView Animation problem with repeating
Hi I am just playing with some basic UIView animation. 嗨,我只是在玩一些基本的UIView动画。 I set the repeat count to 100 so i can see it going up and down over and over.. i set a transition to rotate my view 180 degrees
我将重复计数设置为100,这样我就可以看到它一遍又一遍地上下移动。我设置了一个过渡,可以将视图旋转180度
i can see my view rotating while moving. 我可以看到我的视图在移动时旋转。 however, after some number of repetitions.. the view is still moving up and down, but it is NOT rotating anymore.
但是,经过多次重复后,视图仍在向上和向下移动,但不再旋转。 I don't see the reason why it would stop rotating in the same loop?
我看不出它为什么会在同一循环中停止旋转的原因?
Below is my code: 下面是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
CGAffineTransform trans = CGAffineTransformMakeRotation(M_PI);
Shape* shapeView = [[Shape alloc] initWithShapeName:@"test" frame:CGRectMake(100, 0, 50, 50)];
[self.view addSubview:shapeView];
[UIView beginAnimations:@"test animation" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationRepeatCount:100];
shapeView.transform = trans;
[UIView setAnimationRepeatAutoreverses:YES];
shapeView.frame = CGRectMake(100,300,50,50);
[UIView commitAnimations];
[shapeView release];
} }
Thanks 谢谢
The reason that happens is because you set the animationRepeatAutoreverses after setting the transform. 发生这种情况的原因是因为在设置转换后设置了animationRepeatAutoreverses。 So, every time the shape goes up, that only counts as 1 repetition.
因此,每次形状上升时,这仅算作1次重复。 Whereas the rotation aspect would already count that as 2 repetitions.
而轮换方面已将其计为2次重复。
In other words, the shape moving down and back up is 1 repetition and takes 2 seconds. 换句话说,形状上下移动是1次重复,耗时2秒。 Now, since the rotation wasn't set to autoreverse, the rotation would only take 1 second to complete 1 repetition.
现在,由于未将旋转设置为自动反转,因此旋转只需1秒即可完成1次重复。 So, by the time the shape is back up, the rotation part already made 2 repetitions.
因此,到形状恢复时,旋转部分已经进行了2次重复。 That means that the rotation will end after 100 seconds while the up and down animation will end after 200 seconds.
这意味着旋转将在100秒后结束,而向上和向下动画将在200秒后结束。
I hope I was able to explain that clearly. 我希望我能够清楚地解释这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.