[英]UITapGestureRecognizer doesn't fire up on UIView Subclass
我已經創建了UIView的自定義子類,因為我需要覆蓋drawRect方法。 我嘗試添加一個UITapGestureRecognizer,但這對我不起作用。 這里,我的ViewController的代碼:
MyCustomView *customView = [[MyCustomView alloc] initWithFrame:CGRectFrame(0, 30, 30, 30)];
[customView setUserInteractionEnabled:YES];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSomething)];
[customView addGestureRecognizer:tapGestureRecognizer];
我不明白為什么當我觸摸我的UIView子類對象時,手勢識別器不會啟動。
非常感謝提前!
固定了!
我的觀點是在UIImageView上,而UIImageView沒有將userInteractionEnabled
設置為YES。
固定了!
我的觀點是在UIImageView上,而UIImageView沒有將userInteractionEnabled
設置為YES。
確保你在某處顯示它( addSubview
)。
還要確保userInteractionEnabled設置為true。 如果這是真的,請發布創建並掛鈎手勢識別器的代碼。
在要添加的子視圖上將UserInteractionEnable檢查設置為true,並在選擇器方法中,將對象與其一起傳遞,即
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSomething:)];
並將選擇器方法設為
-(void) doSomething:(UITapGestureRecognizer *)gesture;
如果您還有問題,請告訴我。 謝謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.