How can I stop an UIViewAnimationOptionRepeat UIVi

2019-07-13 10:49发布

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条回答
家丑人穷心不美
2楼-- · 2019-07-13 11:09

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!

查看更多
登录 后发表回答