How to stop an UIView animation

2019-03-09 01:09发布

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?

1条回答
成全新的幸福
2楼-- · 2019-03-09 01:49
 #import <QuartzCore/QuartzCore.h>

then

 [myView.layer removeAllAnimations];

or

[self.view.layer removeAllAnimations]; 
查看更多
登录 后发表回答