鼠标事件通过NSView流血 [英] Mouse Events Bleeding Through NSView

查看:215
本文介绍了鼠标事件通过NSView流血的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSView涵盖了其父窗口的内容视图.该视图具有单击事件处理程序,该事件处理程序会将其从内容视图中删除.在此视图内,我有另一种视图.当我在此内部视图中拖动鼠标时,鼠标事件不仅会应用于前面的视图,还会应用于后面的视图.此外,后面视图中的光标也会显示出来.这是在这里发生的相同问题: NSView叠加层将鼠标事件传递到基础子视图?,但是那里的答案对我的项目不起作用,因为我无法打开另一个窗口.

I have an NSView which covers its parent window's content view. This view has a click event handler which removes it from the content view. Inside this view, I have another view. When I drag the mouse in this inner view, the mouse events are applied not only to the view in the front, but also to the views behind. Additionally, the cursors from the views behind are showing up as well. This is the same problem occurring here: NSView overlay passes mouse events to underlying subviews? but the answer there won't work for my project because I can't open another window.

推荐答案

没有看到事件处理代码,很难知道发生了什么,但是我怀疑您可能正在调用super的各种事件处理实现实现中的方法.

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.

NSViewNSResponder的子类,因此默认情况下,未处理的事件沿响应者链传递.视图的超级视图是响应者链中的下一个对象,因此,如果在实现‑mouseDown:的过程中调用例如[super mouseDown:event],则事件将传递给超级视图.

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.

解决方法是确保您不要在事件处理程序中调用super的实现.

The fix is to ensure you don't call super's implementation in your event handlers.

这是不正确的:

- (void)mouseDown:(NSEvent*)anEvent
{
    //do something
    [super mouseDown:event];
}

这是正确的:

- (void)mouseDown:(NSEvent*)anEvent
{
    //do something
}

这篇关于鼠标事件通过NSView流血的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆