单击通过NSView [英] Click through NSView

查看:586
本文介绍了单击通过NSView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 NSView 包含多个子视图。其中一个子视图是透明的,并在顶部分层。

I have an NSView containing multiple subviews. One of those subviews is transparent and layered on top.

我需要能够点击这个视图到下面的子视图(以便下面的视图获得第一响应状态),但是所有鼠标事件都停留在顶视图上(alpha是 1 ,因为我在其中绘制内容 - 所以它只应该点击透明区域)。

I need to be able to click through this view down to the subviews below (so that the view below gets first responder status), but all the mouse events get stuck on the top view (alpha is 1, because I draw stuff in it - so it should only click through transparent areas).

我实际上期望这个工作,因为通常它。有什么问题?

I actually expected this to work, since normally it does. What's wrong?

推荐答案

这里是另一种方法。它不需要创建一个新的窗口对象,并且比上面的findNextSiblingBelowEventLocation:方法更简单(也可能更高效)。

Here's another approach. It doesn't require creating a new window object and is simpler (and probably a bit more efficient) than the findNextSiblingBelowEventLocation: method above.

- (NSView *)hitTest:(NSPoint)aPoint
{
    // pass-through events that don't hit one of the visible subviews
    for (NSView *subView in [self subviews]) {
        if (![subView isHidden] && [subView hitTest:aPoint])
            return subView;
    }

    return nil;
}

这篇关于单击通过NSView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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