iPhone UIView Animation problem with repeating
Hi I am just playing with some basic UIView animation. I set the repeat count to 100 so i can see it going up and down over and ove开发者_JAVA技巧r.. i set a transition to rotate my view 180 degrees
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. So, every time the shape goes up, that only counts as 1 repetition. Whereas the rotation aspect would already count that as 2 repetitions.
In other words, the shape moving down and back up is 1 repetition and takes 2 seconds. Now, since the rotation wasn't set to autoreverse, the rotation would only take 1 second to complete 1 repetition. So, by the time the shape is back up, the rotation part already made 2 repetitions. That means that the rotation will end after 100 seconds while the up and down animation will end after 200 seconds.
I hope I was able to explain that clearly.
精彩评论