[英]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.