如何停止UIView动画

时间:2021-03-09 20:22:42

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.

我在UIScrollView中有几个UIImageViews,当用户长按其中一个时我想摆动。这与您长按iPad / iPhone菜单中的图标时的行为类似。

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...

这很好用。问题是......如何在用户按下按钮后停止摆动?我有一个按钮并连接它等它到达stopWiggling方法,所以没关系。但是......

  1. How do I remove the UIView animation from these UIImageViews?
  2. 如何从这些UIImageViews中删除UIView动画?
  3. Can I bind this action to the user pressing the home button on their device?
  4. 我可以将此操作绑定到用户按下设备上的主页按钮吗?

1 个解决方案

#1


71  

 #import <QuartzCore/QuartzCore.h>

then

然后

 [myView.layer removeAllAnimations];

or

要么

[self.view.layer removeAllAnimations]; 

#1


71  

 #import <QuartzCore/QuartzCore.h>

then

然后

 [myView.layer removeAllAnimations];

or

要么

[self.view.layer removeAllAnimations];