本文介绍了添加子视图后,NSView鼠标事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将子视图添加到NSView之后,鼠标事件将响应NSView的区域减去addedSubVIew.我该如何避免呢?我希望它对所有Superview做出回应.谢谢.

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.

推荐答案

您还可以在容器视图中实现hitTest:方法.

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.

这篇关于添加子视图后,NSView鼠标事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 22:32