簡體   English   中英

調用Superview的UILongPressGestureRecognizer而不是Subview

[英]UILongPressGestureRecognizer of Superview gets called instead of Subview


我有一個奇怪的問題。 我有一個帶有customcontrols作為子視圖的Superview。 它們是Superview和Subview中的GestureRecognizer。
如果我點擊一個子視圖,它的GestureRecognizer被調用,而在父視圖上,它的水龍頭被調用。
但是有時在子視圖中長按時會調用超級視圖的GestureRecognizer。 我在相同的功能中添加了GestureRecognizers,但態度有所不同。
監督

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPiece:)];
tapGesture.numberOfTapsRequired = 1;
//contenView is the area where my controls can be
[self.contentView addGestureRecognizer:tapGesture];
[tapGesture release];

UILongPressGestureRecognizer *longTapGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTapPiece:)];
tapGesture.numberOfTapsRequired = 1;
[self.contentView addGestureRecognizer:longTapGesture];
[longTapGesture release];

子檢視

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectPiece:)];
tapGesture.numberOfTapsRequired = 1;
[self addGestureRecognizer:tapGesture];

UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPiece:)];
longPressGesture.numberOfTapsRequired = 1;
[self addGestureRecognizer:longPressGesture];

誰能告訴我為什么長按鍵不響應我的子視圖以及如何解決它。
謝謝

有一個解決方案,但這不是我想要的,我將控件的持續時間設置為低於超級視圖之一[longPressGesture setMinimumPressDuration:0.4]; 但是手勢識別器應該是獨立的

暫無
暫無

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

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