Ios – Cancel a UIView animation

core-animationiosuiviewanimation

Is it possible to cancel a UIView animation while it is in progress? Or would I have to drop to the CA level?

i.e. I've done something like this (maybe setting an end animation action too):

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
// other animation properties

// set view properties

[UIView commitAnimations];

But before the animation completes and I get the animation ended event, I want to cancel it (cut it short). Is this possible? Googling around finds a few people asking the same question with no answers – and one or two people speculating that it can't be done.

Best Answer

Use:

#import <QuartzCore/QuartzCore.h>

.......

[myView.layer removeAllAnimations];