在超级视图上获取鼠标按下事件
我有一个 NSScrollView ,它的文档视图是一个名为 MasterPage 的 NSView 子视图。在 MasterPage 上,我有一堆(取决于用户输入)子视图(来自名为 Page 的类)。它们以网格格式布局。我正在尝试捕获鼠标在 MasterPage 上单击的 NSPoint
。它适用于没有子视图的情况,但如果单击的点位于子视图的区域内,则超级视图不会注册它。有办法做到这一点吗?我希望这是有道理的。
红色区域在超级视图的 .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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的 MasterPage 类中,您可以覆盖 NSView 的
-hitTest:
方法并让它返回self
而不是Page
子视图之一。请参阅 事件处理指南:鼠标和平板电脑事件的路径。在此示例项目中, http://www.markdouma.com/developer/SubviewSuperview.zip,您可以观察日志记录调用以查看
NSView
接收事件。如果按住 Alt/Option 键并单击,白色视图将覆盖-hitTest:
并返回自身,从而阻止灰色视图接收事件。In your
MasterPage
class, you could overrideNSView's
-hitTest:
method and have it returnself
rather than one of thePage
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.