在超级视图上获取鼠标按下事件

发布于 2024-12-05 23:12:55 字数 363 浏览 3 评论 0原文

我有一个 NSScrollView ,它的文档视图是一个名为 MasterPage 的 NSView 子视图。在 MasterPage 上,我有一堆(取决于用户输入)子视图(来自名为 Page 的类)。它们以网格格式布局。我正在尝试捕获鼠标在 MasterPage 上单击的 NSPoint 。它适用于没有子视图的情况,但如果单击的点位于子视图的区域内,则超级视图不会注册它。有办法做到这一点吗?我希望这是有道理的。

红色区域在超级视图的 .m 文件中注册鼠标单击。四个子视图没有。

红色区域在超级视图的 .m 文件中记录了鼠标单击。四个子视图则没有。

I have an NSScrollView and its document view is an NSView subview titled MasterPage. On MasterPage I have a bunch (depending on user input) of subviews (from a class called Page).They are laid out in a grid format. I'm trying to capture the NSPoint of the mouse click on MasterPage. It works where there are no subviews but if the point clicked is within the area of a subview then the superview does not register it. Is there a way to do this? I hope that makes sense.

The red area registers a mouse click in the superview's .m file. The four subviews do not.

The red area registers a mouse click in the superview's .m file. The four subviews do not.

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

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

发布评论

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

评论(1

烟花易冷人易散 2024-12-12 23:12:55

In your MasterPage class, you could override NSView's -hitTest: method and have it return self rather than one of the Page subviews. See Event Handling Guide: The Path of Mouse and Tablet Events.

In this example project, http://www.markdouma.com/developer/SubviewSuperview.zip, you can watch the logging calls to see what NSView receives the events. If you hold down the Alt/Option key and click, the white view will override -hitTest: and return itself, preventing the gray views from receiving the event.

enter image description here

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