开发者

Getting mouse down event on superview

I have an NSScrollView and its document view is an NSView subview titled MasterPage. On MasterPage I have a bunch (dependin开发者_高级运维g 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.

Getting mouse down event on superview


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.

Getting mouse down event on superview

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜