![](/img/trans.png)
[英]UILongPressGestureRecognizer gets called twice when pressing down
[英]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.