Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top