如何停止 UIView 动画

发布于 2024-12-01 20:02:48 字数 962 浏览 0 评论 0原文

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

所以我有以下内容:

- (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 方法,所以没关系。但是那么...

  1. 如何从这些 UIImageViews 中删除 UIView 动画?
  2. 我可以将此操作绑定到用户按下设备上的主页按钮吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明月松间行 2024-12-08 20:02:48
 #import <QuartzCore/QuartzCore.h>

那么

 [myView.layer removeAllAnimations];

或者

[self.view.layer removeAllAnimations]; 
 #import <QuartzCore/QuartzCore.h>

then

 [myView.layer removeAllAnimations];

or

[self.view.layer removeAllAnimations]; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文