我想要通过动画移动一个UIButton,在移动过程中,如果用户触摸它,我希望能够识别到这个事件,但在动画期间,UIButton不会发送任何事件。
请帮我解决这个问题。
请帮我解决这个问题。
你尝试过使用AllowUserInteraction选项吗?
[UIView animateWithDuration:5.0
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{ // move the button }
completion:^(BOOL finished){}];
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
在父视图中捕获事件并查看事件是否指向按钮。
由于UIButton
继承自UIControl
,而UIControl
又继承自UIView
,因此我相信您正在使用基于块的方法来动画化您的按钮animateWithDuration:delay:options:animations:completion:
当您动画化您的UIButton
时,您需要添加选项UIViewAnimationOptionAllowUserInteraction
以允许识别某些用户交互。否则,默认情况下在动画期间禁用用户交互。