Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Stop a repeating UIAnimation?

I have an animation that needs to be repeated until I decided to stop it.

How can I stop in animation after a button click?

[UIView animateWithDuration:0.2 delay:0 options:(UIViewAnimationCurveLinear | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat) animations:^{

        CGAffineTransform transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(5));
        self.transform = transform;

    }  completion:^(BOOL finished){

    }];
like image 325
aryaxt Avatar asked Dec 06 '22 15:12

aryaxt


1 Answers

You have to add one other option UIViewAnimationOptionAllowUserInteraction ...

You should try this:

[UIView animateWithDuration:2 delay:0 options:UIViewAnimationCurveLinear | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction animations:^
{
    view.frame = CGRectMake(0, 100, 200, 200);
} completion:^(BOOL finished)
{
    if(! finished) return;
}];

And to stop the animation use this:

[view.layer removeAllAnimations];
like image 180
Nirav Gadhiya Avatar answered Jan 02 '23 06:01

Nirav Gadhiya