[英]How to recognize touch event while a UIButton is animating
我想用动画移动一个UIButton,当它移动时如果用户触摸它,我想要识别该事件,但在动画期间UIButton不发送任何事件。
请解决我的问题。
你试过AllowUserInteraction选项吗?
[UIView animateWithDuration:5.0
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{ // move the button }
completion:^(BOOL finished){}];
在动画期间,无论此属性中的值如何,都会暂时禁用动画中涉及的所有视图的用户交互。 您可以通过在配置动画时指定UIViewAnimationOptionAllowUserInteraction选项来禁用此行为。
此外,您可以实施
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
在superview中捕获事件并查看事件是否指向按钮。
由于UIButton
继承自继承UIView
UIControl
,我相信您正在使用基于块的方法为您的按钮设置动画animateWithDuration:delay:options:animations:completion:
在为UIButton设置动画时,您需要添加选项UIViewAnimationOptionAllowUserInteraction
以允许识别某些用户交互。 在实验中,默认情况下,在动画期间禁用用户交互。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.