如何停止UIViewAnimationOptionRepeat 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; } }]; 

然后,当我想停止animation时,我发送以下消息到视图本身:

 [[self layer] removeAllAnimations]; 

但它什么都不做…我怎样才能停止animation?

我使用以下代码修复了这个问题:

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

并在ViewController中调用它。

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