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){
}];
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With