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...
UIImageViews
?Using the .animation(nil) view modifier to disable animations.
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.
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.
UIView. animate runs on the main thread and is asynchronous.
#import <QuartzCore/QuartzCore.h>
then
[myView.layer removeAllAnimations];
or
[self.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