取消UIViewanimation

我使用下面的代码摇button我怎样才能取消它,当它正在进行?

#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 [UIView commitAnimations]; 

你可以使用CALayerremoveAllAnimations方法:

 [btn.layer removeAllAnimations];