如何停止UIViewAnimationOptionRepeat UIView动画?

时间:2013-12-08 15:49:44

标签: ios iphone uiview ios7 uiviewanimation

我在UIView子类中有以下代码:

[element setAlpha: 0.0f];

[UIView animateWithDuration: 0.4 delay: 0.0 options: UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations: ^{
    [element setAlpha: 1.0f];
} completion: ^(BOOL finished){
    if (finished) 
    {
        return;
    }
}];

然后当我想停止动画时,我将以下消息发送给View本身:

[[self layer] removeAllAnimations];

但它什么都不做......我怎么能停止动画?

1 个答案:

答案 0 :(得分:4)

我使用以下代码修复:

- (void)restoreAnimations {

    [UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveLinear animations:^{
        [element setAlpha: 1.0f];
    } completion:NULL];
}

在ViewController中调用它。

顺便说一下。非常感谢Malloc!