UIButton在动画期间没有交互 [英] UIButton not interacting during animation

查看:221
本文介绍了UIButton在动画期间没有交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为UIButton制作动画。但在动画期间,没有与UIButton的互动。预期的行为是能够在按钮移动时单击按钮。这是UIButton和动画的代码片段:

I'm trying to animate a UIButton. But during it's animation, there is no interaction with the UIButton. Expected behavior is to be able to click on the button while it's moving. Here's the code snippet of the UIButton and animation:

UIImage *cloudImage = [UIImage imageNamed:@"sprite.png"];    
UIButton moveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[moveBtn setFrame:CGRectMake(0.0, 80.0, cloudImage.size.width, cloudImage.size.height)];
[moveBtn setImage:cloudImage forState:UIControlStateNormal];
[moveBtn addTarget:self action:@selector(hit:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:moveBtn];
CGPoint newLeftCenter = CGPointMake( 300.0f + moveBtn.frame.size.width / 2.0f, moveBtn.center.y);
[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:5.0f];
[UIView setAnimationRepeatCount:HUGE_VALF];
moveBtn.center = newLeftCenter;
[UIView commitAnimations];

点击选择器只显示一个NSLog来显示如果按钮响应它。任何帮助将不胜感激。

hit selector just displays an NSLog to show if the button respond to it or not. Any help would be appreciated.

推荐答案

最近这里有一些问题。动画纯粹是视觉效果。您可以点击旧框架中的按钮,直到动画完成,完成后,实际按钮会跳跃。

There were some questions here recently about this. The animation is purely visual. You can tap the button in it'd old frame until the animation is complete, when it finishes, the actual button jumps.

编辑:

这个答案是我所指的。显然,您需要使用NSTimer手动移动按钮。有关详细信息,请参阅链接的问题/答案。

This answer is what I was referring to. You need to manually move the button with an NSTimer, apparently. See the linked question/answer for more.

其他人建议将 UIViewAnimationOptionAllowUserInteraction 作为UIViewAnimation选项传递。

Other folks suggest passing UIViewAnimationOptionAllowUserInteraction as a UIViewAnimation option.

这篇关于UIButton在动画期间没有交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆