如何将手势识别器从一个视图传递到另一个视图

我有一个视图,其中包含几个子视图,这些子视图是具有多个按钮的复杂控件 superview具有水龙头,滑动等手势识别器。

在某些情况下,当接收单次或双次触摸时,我希望超级视图将手势识别器传递给子视图进行治疗。

例如:

singletaprecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSingleTapGestureRecognizerDetected:)]; - (void)onSingleTapGestureRecognizerDetected:(UITapGestureRecognizer*)theTapGestureRecognizer { if (someCaseHappens) { // do something with the gesture - for instance - move a control from one place to another or some other UI action in the superview } else { // the subview will need to get the gesture and do something with it (imagine the touch was inside a button in a subview - the top superview should disregard the gesture and the button should be pressed) - THIS ISN"T HAPPENING NOW } } 

好吧,你可以创建一个inheritance自UIView的自定义视图,然后覆盖:

 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event 

通过此方法,您可以返回要处理事件的视图。

请查看: https : //developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/hitTest : withEvent :