如何让NSWindow在打开后立即接受mouseMove事件?
我正在使用可可编写一个应用程序,它在某些时候(令人惊讶)会打开窗口。
该窗口中有一个“悬停”功能,为此我需要接受 mouseMoved 事件。我设法使用
[[newView window] setAcceptsMouseMovedEvents:YES];
调用激活此功能,但是,它只有在我触摸打开的窗口后才开始工作,实际上以这种方式激活它。我希望它能够立即运行,而无需单击它。
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
似乎不起作用,因为只有 mouseDown 或 mouseDragged 事件激活它。显然 mouseMoved 事件没有。
换句话说,mouseMoved 事件仅在 mouseDown 或 mouseDragged 事件被调用后才开始工作。
I am writing an application using cocoa which, in some point (surprise), opens window.
There is a "Hover" functionality in this window, and for that I need to accept mouseMoved events. I managed to activate this functionality using
[[newView window] setAcceptsMouseMovedEvents:YES];
call, however, it only starting to work after I touch the opened window, actually activating it this way. I am interested for it to work right away, without clicking on it.
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
does not seem to be working since only mouseDown or mouseDragged events activate it. Apparently mouseMoved event does not.
In other words, mouseMoved event only start to work after mouseDown or mouseDragged event has been called.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否使用 NSTrackingArea 来处理这个?您是否传入了 NSTrackingActiveAlways 选项?
Are you using an NSTrackingArea to handle this? Have you passed in the NSTrackingActiveAlways option?