简体   繁体   中英

NSView mouse events after adding subview

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.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM