簡體   English   中英

UIButton不響應觸摸事件

[英]UIButton do not respond to touch event

我有一個UIButton不響應觸摸事件。 而且該按鈕只有一些子視圖,無法處理事件。 因此,我用自定義的UIButton替換了它,以了解發生了什么。 下面是我的代碼:

@interface CustomButton : UIButton

@end

@implementation CustomButton

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
}

-(BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
    return [super beginTrackingWithTouch:touch withEvent:event];
}
@end

我發現touchesBegan:withEvent:方法被調用了,但是從未調用beginTrackingWithTouch:withEvent: 似乎該事件已調度到我的按鈕上,但是我不明白為什么從未跟蹤該事件。 任何線索將不勝感激。

禁用按鈕上方未監聽事件的視圖的用戶交互。 檢查按鈕是否啟用了用戶交互。 檢查UIButton的框架大小,並確保它不為零(特別是在以編程方式使用自動布局時)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM