2011-04-06 64 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应该影响无关

相关问题