Mouse Events Bleeding Through NSView
Without seeing your event-handling code it's difficult to know what's happening, but I suspect you might be calling super
's implementation of the various event-handling methods in your implementations.
NSView
is a subclass of NSResponder
, so by default un-handled events are passed up the responder chain. The superview of a view is the next object in the responder chain, so if you call, for example, [super mouseDown:event]
in your implementation of ‑mouseDown:
, the event will be passed to the superview.
The fix is to ensure you don't call super
's implementation in your event handlers.
This is incorrect:
- (void)mouseDown:(NSEvent*)anEvent
{
//do something
[super mouseDown:event];
}
This is correct:
- (void)mouseDown:(NSEvent*)anEvent
{
//do something
}
Rob's answer and Maz's comment on that answer solve this issue, but just to make it absolutely explicit. In order to prevent a NSView from bleeding it's mouse events to the parent, one must implement the empty methods.
// NSResponder =========================================
- (void) mouseDown:(NSEvent*)event {}
- (void) mouseDragged:(NSEvent*)event {}
- (void) mouseUp:(NSEvent*)event {}