I have two NSViews on top of each other. One NSView presents a table with rows. On clicking a row another view is shown on top of that view.
Now the problem is when I click on an area on the second view where there is a row on the underneath NSView then it gets clicked. How can I stop that?
Thanks
On your top level view, implement mouseDown:
in that view and do not call nextResponder or do anything in it.
- (void)mouseDown:(NSEvent *)theEvent{
//Do nothing to not propagate the click event to descendant views
}
I have the exact same scenario as the OP and this is working for me as intended. Credit to the answer I found here that led me to this.
Subclass and implement acceptsFirstMouse
in the view, returning YES
. Also, set acceptsTouchEvents
to YES
in that view.
import Cocoa
class UnView: NSView{
override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
return false
}
override var allowedTouchTypes: NSTouch.TouchTypeMask {
get { return [] }
set { }
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With