2011-04-06 51 views
1


我遇到了一個奇怪的問題。我用customcontrols作爲子視圖獲得了Superview。 他們是在superview和子視圖中的GestureRecognizer。
如果我點擊一個子視圖,它的GestureRecognizer會被調用,然後點擊superview上的tap會被調用。
但在子視圖中長按SOMETIMES會調用superview的GestureRecognizer。我將GestureRecognizers添加到相同的功能中,但是態度不同。
的SuperViewSuperview的UILongPressGestureRecognizer被調用而不是子視圖

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]; 

誰能告訴我,爲什麼longtap doen't回答我的子視圖,以及如何解決它。
THANK YOU

+0

得到了一個解決方案更低的持續時間,但是這不是我想我設置控件的持續時間低於superview '[longPressGesture setMinimumPressDuration:0.4];'但是gestureRecognizer應該是獨立的 – Seega 2011-04-06 09:53:26

+0

你好,我遇到了同樣的問題。請參閱:http://stackoverflow.com/questions/25756615/uiimageview-cant-detect-long-press-gesture-in-a-customized-swippable-uitablevie – Vigor 2014-09-10 14:19:36

回答

1

得到了一個解決方案,但是這不是我想要的我設定的控制比上海華[longPressGesture setMinimumPressDuration:0.4];的一個但gestureRecognizer應該影響無關

相關問題