setAnimationRepeatAutoreverses not behaved as I expected

Posted by danielkwan on Stack Overflow See other posts from Stack Overflow or by danielkwan
Published on 2010-03-25T14:12:32Z Indexed on 2010/03/25 14:23 UTC
Read the original article Hit count: 557

Filed under:
|

I am starting to learn to use UIView animation. So I wrote the following lines:

 [UIView beginAnimations:nil context:NULL];

 [UIView setAnimationDuration:2.0];
 [UIView setAnimationRepeatCount:2];
 [UIView setAnimationRepeatAutoreverses:YES];

 CGPoint position = greenView.center;
 position.y = position.y + 100.0f;
 position.x = position.x + 100.0f;
 greenView.center = position;

 [UIView commitAnimations];

In this case, the UIView (a green box) moved back and fore 2 times. So far so good, BUT I found out that after the moving twice, the green box ended up jumped to the "new position" (position.x + 100.0f, position.y + 100.0f) instead of going back to the original position (position.x, position.y). That makes the animation look pretty odd (like after the box swing back to the original position caused by setAnimationRepeatAutoreverses, it jumps back to the new position in the last microsecond!)

What is the best way to make the green box NOT jump to the new position at the very last minute?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about core-animation