views:

35

answers:

1

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
    [UIView commitAnimations];
+2  A: 

You can use CALayer's removeAllAnimations method:

[btn.layer removeAllAnimations];
Jacob Relkin