iOS - 如何将触摸转发到底层 uiview [英] iOS - how to forward touches to the underlying uiview

查看:37
本文介绍了iOS - 如何将触摸转发到底层 uiview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 3 个相同大小的 UIViews 堆叠在一起.最上面是透明的,仅用于检测触摸.检测到的触摸类型将决定我想要接收触摸事件的其他两个底层视图中的哪一个.一旦最顶层的视图完成触摸,我需要将触摸事件转发到正确的底层视图.我该怎么做?

I have 3 UIViews of the same size stacked on top of each other. The topmost is transparent and only used for detecting touches. The type of touch detected will determine which of the other two underlying views I want to receive the touch events. Once the topmost view is finished with the touch, I need to forward the touch events to the correct underlying view. How can I do that?

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

EDIT - I am adding my touch detection code. This is within MainViewController, whose view contains all 3 subviews.

-(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 并处理父视图中的所有触摸.然后,根据触摸类型,向正确的视图发送编程触摸事件.那么你就不需要顶部的清晰视野.基本上,您将自下而上协调触摸事件,而不是从顶部->底部->中间.

Make your two subviews setUserInteractionEnabled:NO and handle all touches in the parent. Then, depending on touch type, send the correct view a programatic touch event. Then you don't need your clear view on the top. Basically you will be coordinating touch events from the bottom up instead of going top->bottom->middle.

这篇关于iOS - 如何将触摸转发到底层 uiview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆