【问题标题】:cancel UIView Animation取消 UIView 动画
【发布时间】:2010-10-26 05:12:10
【问题描述】:

我使用下面的代码作为摇动按钮,当它正在进行时如何取消它?

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

【问题讨论】:

  • 我相信2018年最好的办法就是使用UIViewPropertyAnimator

标签: ios


【解决方案1】:

你可以使用CALayerremoveAllAnimations方法:

[btn.layer removeAllAnimations];

【讨论】:

    猜你喜欢
    • 2010-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多