问题描述
这里是个主意:
我有一个包含2个NSView的NSWindow,我们将它们称为ViewA和ViewB.
I have a NSWindow containing 2 NSView, let's call them ViewA and ViewB.
ViewA有一个子视图对象列表,每个对象都有自己的跟踪区域集,并处理mouseDown事件. ViewB是一个隐藏视图,显示在ViewA上方.
ViewA has a list of subview objects, each object has its own tracking area set and handles a mouseDown event. ViewB is a hidden view, which appears above ViewA.
问题是,当ViewB出现时,ViewA仍会收到mouseDown事件.因此,当我单击ViewB时,ViewB后面的对象会收到mouseDown事件.我想知道在ViewB结束时是否有任何方法可以阻止ViewA的事件.
The problem is when ViewB appears, ViewA still receives mouseDown events. So when I click on ViewB, the object behind the ViewB receives the mouseDown event. I would like to know if there's any way to block the events of ViewA while ViewB is over it.
我知道我可以从每个对象中删除跟踪区域,但它仍会响应mouseDown事件.
I know I can remove the tracking area from every object, but it still responds to the mouseDown event.
推荐答案
您还可以通过[ViewA setAcceptsTouchEvents:NO];
禁用ViewA的触摸事件并可以根据需要通过再次设置YES
再次启用它们.
you can also disable the touch events for ViewA by [ViewA setAcceptsTouchEvents:NO];
and can enable them again as per your requirement by setting YES
again.
这篇关于如何在另一个NSView下阻止NSView事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!