4
votes

After I add a subview to NSView, my mouse events respond to the area of NSView minus the addedSubVIew. How can I avoid that? I want it to respond on all of the superview. Thanks.

2

2 Answers

3
votes

You can also implement the hitTest: method in the container view.

- (NSView *) hitTest: (NSPoint) aPoint {
    return [super hitTest:aPoint] ? self : nil;
}

Now only the container view can receive the mouse events.

2
votes

You can override the subviews [NSView hitTest:] method and return the superview.

- (NSView *) hitTest: (NSPoint) aPoint {
    return [self superview];
}