我有3个相同大小的UIView彼此堆叠。最顶部是透明的,仅用于检测触摸。检测到的触摸类型将确定我要接收其他两个基础视图中的哪个视图。触摸完成最上面的视图后,我需要将触摸事件转发到正确的基础视图。我怎样才能做到这一点?

编辑-我正在添加我的触摸检测代码。这在MainViewController中,其视图包含所有3个子视图。

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{

    for (UITouch *touch in touches)
    {
        if (touch.view == self.touchOverlay) {
            CGPoint touchLocation = [touch locationInView:touch.view];

            //do a bunch of math to determine which view should get the touches.
            if (viewAshouldGetTouches) //forward to viewA
            if (viewBshouldGetTouches) //forward to viewB


        }
    }
}

最佳答案

将两个子视图设为setUserInteractionEnabled:NO并处理父视图中的所有触摸。然后,根据触摸类型,向正确的视图发送程序化的触摸事件。这样一来,您就无需在顶部看到清晰的视图。基本上,您将自下而上地协调触摸事件,而不是从顶部->底部->中间进行协调。

10-07 19:43
查看更多