Alex Tarragó
Alex Tarragó

Reputation: 966

How can I stop an UIViewAnimationOptionRepeat UIView Animation?

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?

Upvotes: 3

Views: 3653

Answers (1)

Alex Tarragó
Alex Tarragó

Reputation: 966

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!

Upvotes: 4

Related Questions