cancel UIView Animation
I use below code for shake button How can i cancel it when it's in progress?
#define RADIANS(degrees) ((degrees * M_PI) / 180.0)
CGAffineTransform leftWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(-10.0));
CGAffineTransform rightWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(10.0));
btn.transform = leftWobble; // starting point
[UIView beginAnimations:@"wobble" context:btn];
[UIView setAnimationRepeatAutoreverses:YES]; // important
[UIView setAnimationRepeatCount:20];
[UIView setAnimationDuration:0.1];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(wobbleEnded:finished:context:)];
btn.transform = rightWobble; // end here & auto-reverse
[UI开发者_如何学CView commitAnimations];
You can use CALayer
's removeAllAnimations
method:
[btn.layer removeAllAnimations];
精彩评论