Stop an infinite repeating UIView block animation

Imagine you have a repeating animation created with the UIView block animation method and you want to stop.

So your creation looks like this:

[UIView animateWithDuration:2.0 delay:0.0 
options:(UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse)
animations:^{
    [myImageview setAlpha:1.0];
}completion:^(BOOL finished){
}];

You can just stop this animation by  commiting a fast animation to the final value you want to have, in my case alpha 0

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.1];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
[myImageview setAlpha:0.0];
[UIView commitAnimations];

source: http://stackoverflow.com/questions/554997/cancel-a-uiview-animation

source that didn’t work for me, as first guess because I am using an UIImageView:

http://stackoverflow.com/questions/7204602/how-to-stop-an-uiview-animation

Leave a Reply

Your email address will not be published. Required fields are marked *