Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop an UIView animation

I have several UIImageViews within a UIScrollView that I want to wiggle when the user long-presses one of them. So similar to the behavior you get when you long-press an icon in your iPad/iPhone menu.

So I have the following:

- (void)startWiggling {      for (UIImageView *touchView in [scrollView subviews]) {          [UIView beginAnimations:@"wiggle" context:nil];         [UIView setAnimationDuration:0.1];         [UIView setAnimationRepeatAutoreverses:YES];         [UIView setAnimationRepeatCount:FLT_MAX];          //wiggle 1 degree both sides         touchView.transform = CGAffineTransformMakeRotation();         touchView.transform = CGAffineTransformMakeRotation(-0.0174532925);          [UIView commitAnimations];      }      }  - (void)stopWiggling {     NSLog(@"Stop wiggling");     } 

This works fine. The issue is... How can I make it stop wiggling after the user has pressed a button? I have a button and connected it etc and it's reaching the stopWiggling method, so that's fine. But so...

  1. How do I remove the UIView animation from these UIImageViews?
  2. Can I bind this action to the user pressing the home button on their device?
like image 924
Jules Avatar asked Aug 26 '11 12:08

Jules


People also ask

How to stop animation in swift?

Using the .animation(nil) view modifier to disable animations.

How to stop animation in iOS?

How to disable motion on iPhone or iPad. Open the Settings app and tap Accessibility. Select Motion. Turn on Reduce Motion to disable the screen animations.

Does UIView animate need weak self?

You don't need to use [weak self] in static function UIView. animate() You need to use weak when retain cycle is possible and animations block is not retained by self.

Is UIView animate asynchronous?

UIView. animate runs on the main thread and is asynchronous.


1 Answers

 #import <QuartzCore/QuartzCore.h> 

then

 [myView.layer removeAllAnimations]; 

or

[self.view.layer removeAllAnimations];  
like image 79
Vijay-Apple-Dev.blogspot.com Avatar answered Sep 24 '22 19:09

Vijay-Apple-Dev.blogspot.com