Cancel a UIView animation? Cancel a UIView animation? ios ios

Cancel a UIView animation?


Use:

#import <QuartzCore/QuartzCore.h>.......[myView.layer removeAllAnimations];


The way I do it is to create a new animation to your end point. Set a very short duration and make sure you use the +setAnimationBeginsFromCurrentState: method to start from the current state. When you set it to YES, the current animation is cut short. Looks something like this:

[UIView beginAnimations:nil context:NULL];[UIView setAnimationBeginsFromCurrentState:YES];[UIView setAnimationDuration:0.1];[UIView setAnimationCurve: UIViewAnimationCurveLinear];// other animation properties// set view properties[UIView commitAnimations];


Simplest way to stop all animations on a particular view, immediately, is this:

Link the project to QuartzCore.framework. At the start of your code:

#import <QuartzCore/QuartzCore.h>

Now, when you want to stop all animations on a view dead in their tracks, say this:

[CATransaction begin];[theView.layer removeAllAnimations];[CATransaction commit];

The middle line would work all by itself, but there's a delay until the runloop finishes (the "redraw moment"). To prevent that delay, wrap the command in an explicit transaction block as shown. This works provided no other changes have been performed on this layer in the current runloop.