How can I stop an UIViewAnimationOptionRepeat UIView Animation?

故事扮演 提交于 2019-12-10 21:27:05

问题


I have the following code inside of a UIView subclass:

[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;
    }
}];

Then when I want to stop the Animation I send the following message to the View itself:

[[self layer] removeAllAnimations];

But it does nothing... How can I stop the animation?


回答1:


I fixed using the following piece of code:

- (void)restoreAnimations {

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

And calling it in the ViewController.

Btw. Thanks a lot Malloc!



来源:https://stackoverflow.com/questions/20455357/how-can-i-stop-an-uiviewanimationoptionrepeat-uiview-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!