覆盖检测触摸的 UIView,处理它们并将它们发送到下方视图

Overlay UIView who detect touches, process them and send them to underneath view

我创建了一个视图,它应该处理所有的触摸、滑动...等等。这个视图将始终位于所有其他视图之上,并将覆盖设备屏幕。我想要的是这个视图获取所有事件,以透明的方式处理它们。

我试过使用:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
    NSSet *tmpTouches = [event allTouches];

    if (tmpTouches.count == 1)
        NSLog(@"1 tap detected");
    else if (tmpTouches.count == 2)
        NSLog(@"w tap detected");
    else if (tmpTouches.count == 3)
        NSLog(@"3 tap detected");

    UIView *hitTestView = [super hitTest:point withEvent:event];
    if (hitTestView) {
        hitTestView = nil;
    }
    return hitTestView;
}

但事件中未检测到触摸


在下一个方法中 if return YES 我可以使用 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event ... 等等 但是如何将触摸事件发送到下一个视图。如果 return NO 视图对系统是透明的,但我没有任何接触..

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{   
    return NO;
}

任何帮助将不胜感激!

在您的主视图中引用您的子视图。使用 touchesBegan 等机制来获取您的触摸。在您的主视图中,直接调用应该处理该事件的子视图中的方法。换句话说,主视图吸收事件,然后在子视图中调用适当的方法。这比尝试在两个视图之间分配事件要容易。