简体   繁体   English

调用Superview的UILongPressGestureRecognizer而不是Subview

[英]UILongPressGestureRecognizer of Superview gets called instead of Subview


i got a strange problem. 我有一个奇怪的问题。 I got a Superview with customcontrols as subviews. 我有一个带有customcontrols作为子视图的Superview。 Their are GestureRecognizer both in superview and subviews. 它们是Superview和Subview中的GestureRecognizer。
If i tap a subview its GestureRecognizer gets called and on tap on the superview its tap gets called. 如果我点击一个子视图,它的GestureRecognizer被调用,而在父视图上,它的水龙头被调用。
but on long press in the subview SOMETIMES the GestureRecognizer of the superview gets called. 但是有时在子视图中长按时会调用超级视图的GestureRecognizer。 I add the GestureRecognizers in the same functions but there is a different attitude. 我在相同的功能中添加了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];

Subviews 子检视

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

Can anyone tell me why the longtap doen't response to my subview and how to fix it. 谁能告诉我为什么长按键不响应我的子视图以及如何解决它。
THANK YOU 谢谢

got a solution but this is not what i wanted i set the duration of the control lower than the one of the superview [longPressGesture setMinimumPressDuration:0.4]; 有一个解决方案,但这不是我想要的,我将控件的持续时间设置为低于超级视图之一[longPressGesture setMinimumPressDuration:0.4]; But the gestureRecognizer should be independend 但是手势识别器应该是独立的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM