2012-10-12 38 views
3

我想用动画移动UIButton,当它移动(如果用户触摸它),我想识别该事件,但在动画过程中UIButton不会发送任何事件。如何在UIButton动画时识别触摸事件

请解决我的问题。

+0

[UIButton无法在使用UIView animateWithDuration动画时触及](http://stackoverflow.com/questions/8346100/uibutton-cant-be-touched-while-animated-with-uiview-animatewithduration) – leekaiinthesky

回答

0

在动画过程中,无论此属性中的值如何,都会暂时禁用动画中涉及的所有视图的用户交互。您可以通过在配置动画时指定UIViewAnimationOptionAllowUserInteraction选项来禁用此行为。

此外,您还可以在上海华实现

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 

捕捉事件,看看是否该事件被指向按钮。

6

您是否尝试了AllowUserInteraction选项?

[UIView animateWithDuration:5.0 
         delay:0.0   
        options:UIViewAnimationOptionAllowUserInteraction 
        animations:^{ // move the button } 
       completion:^(BOOL finished){}]; 
0

由于UIButton继承UIControl它继承UIView,我相信你正在使用的基于块的方法来动画的按钮animateWithDuration:delay:options:animations:completion:

您需要添加选项UIViewAnimationOptionAllowUserInteraction当你动画的UIButton的允许识别一些用户交互。正如你试验的,用户交互在动画期间默认是禁用的,否则。