开发者

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜