Superview的UILongPressGestureRecognizer被调用而不是Subview

时间:2011-04-06 09:36:48

标签: iphone objective-c ios uigesturerecognizer


我遇到了一个奇怪的问题。我将自定义控件作为子视图获得了Superview。 他们是超级视图和子视图中的GestureRecognizer 如果我点击子视图,它的GestureRecognizer会被调用,并且在超级视图上点击它的点击 但是在子视图中长按,有时会调用superview的GestureRecognizer。我在相同的功能中添加了GestureRecognizers,但是态度不同 的的SuperView

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不响应我的子视图以及如何解决它。
谢谢你

1 个答案:

答案 0 :(得分:1)

得到了一个解决方案,但这不是我想要的,我将控件的持续时间设置为低于superview [longPressGesture setMinimumPressDuration:0.4];的持续时间但是gestureRecognizer应该是独立的