NSView mouse events after adding subview

安稳与你 提交于 2021-02-19 02:56:06

问题


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.


回答1:


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:


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

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


来源:https://stackoverflow.com/questions/5619199/nsview-mouse-events-after-adding-subview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!