如何停止 UIView 动画

How to stop an UIView animation(如何停止 UIView 动画)

本文介绍了如何停止 UIView 动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UIScrollView 中有几个 UIImageViews,当用户长按其中一个时,我想摆动它们.与长按 iPad/iPhone 菜单中的图标时的行为非常相似.

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.

所以我有以下内容:

- (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");    
}

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

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. 如何从这些 UIImageViews 中移除 UIView 动画?
  2. 我可以将此操作绑定到在其设备上按下主页按钮的用户吗?
  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?

推荐答案

 #import <QuartzCore/QuartzCore.h>

然后

 [myView.layer removeAllAnimations];

[self.view.layer removeAllAnimations]; 

这篇关于如何停止 UIView 动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何停止 UIView 动画