UIResponder链问题

发布于 2024-10-01 04:26:58 字数 487 浏览 0 评论 0原文

我不太了解修改响应者链的细节,所以如果这是愚蠢的,请不要攻击我;)

基本上我有 2 个视图堆栈(蓝色)作为父视图(红色)的子视图,

它们都占据了完整的视图堆栈父视图在某个时间点的框架,因此显然只有顶部的框架正在获取触摸事件,该事件向上传播到父视图(红色)并到达窗口。

在某些情况下,我希望触摸输入由“其他”视图堆栈的合格子视图拾取。也就是说,如果当前最顶层视图将 userinteractionenabled 设置为 no,则该视图将接收这些输入。

设置 userinteractionenabled 有效,但我觉得这是一个肮脏的黑客行为。要点是这个 topmot 视图大部分是透明的,我希望在指定区域中触摸时的事件最终出现在另一个堆栈上。

这是一张有助于直观解释的图片,请记住两个蓝色视图都是 100% 的父视图。

http://c.crap.ps/35a5

Im not too informed on the nitty gritty of modifying the responder chain, so if this is stupid pls dont bash me ;)

basically i have 2 view stacks(blue) as a subview of a parent view(red)

they are both occupying the full frame of parent at one point in time, so obviously only the one on top is getting touch events, which travel upstream to the parent view(red) and on to window.

During some cases i want the touch input to be picked up by the eligible child view of 'other' view stack. That is, the view that woud be receiving these inputs if the current topmost view had userinteractionenabled set to no.

Setting userinteractionenabled works but i feel like its a dirty hack. The gist is this topmot view is mostly transparent and i want the events when touched in the specified region to end up on the other stack.

here is a picture to help visually explain, and keep in mind both blue views are 100% of parent.

http://c.crap.ps/35a5

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

芸娘子的小脾气 2024-10-08 04:26:58

您可以在每个视图中重写 hitTest:withEvent: 来控制谁可以“消耗”触摸。

在您的示例中,我假设绿色区域是您想要使用触摸事件的子视图。如果是这样,请尝试使用 hitTest 方法:

-(UIView*) hitTest:(CGPoint)point withEvent:(UIEvent *)event {  
    UIView *hitView = [super hitTest:point withEvent:event];
    return (hitView == self) ? nil : hitView;
}

此方法检查触摸是否击中任何子视图。如果是,则它让该子视图消耗触摸,否则它让触摸继续通过层次结构。

You can override hitTest:withEvent: in each of the views to control who gets to "consume" the touch.

In your example I am assuming that the greenish areas are subviews that you want to consume the touch events. If so, then try this for the hitTest method:

-(UIView*) hitTest:(CGPoint)point withEvent:(UIEvent *)event {  
    UIView *hitView = [super hitTest:point withEvent:event];
    return (hitView == self) ? nil : hitView;
}

This method checks if the touch hits any of the subviews. If it does then it lets that subview consume the touch, otherwise it lets the touch continue through the hierarchy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文