我有一个应用程序,使用 orderOut 和 orderFront 显示和隐藏无边框窗口。当它可见时,我希望当鼠标移到它上面时它成为关键窗口。
到目前为止,我已经这样做了:
- 在 awakeFromNib 中,我已将其第一响应者设置为自身。
- 在窗口的构造函数中,我将接受鼠标事件设置为“是”。
- 在 mouseMoved 方法中,我使用 makeKeyAndOrderToFront。
我的问题是,这仅在我第一次将鼠标移到窗口上时才有效。
之后,它不会收到任何 mouseOver 事件。
我尝试检查firstResponder,但据我所知它永远不会从窗口发生变化。
有什么想法我可以做些什么来让它发挥作用吗?
I have an application where a borderless window is shown and hidden, using orderOut and orderFront. When it is visible, I want the it to become the key window when the mouse moves over it.
So far I've done this:
- In awakeFromNib I have set its first responder to itself.
- In the window's constructor I set accepts mouse events to YES.
- In the mouseMoved method, I use makeKeyAndOrderToFront.
My problem is, that this only works the first time I move the mouse over the window.
After that, it doesn't receive any mouseOver events.
I've tried checking the firstResponder but as far as I can tell it never changes from the window.
Any ideas what I can do to get this working?
发布评论
评论(2)
您需要添加跟踪区域 如果你想接收
mouseMoved
事件(我假设这就是你的意思,因为 Cocoa 没有mouseOver
事件之类的东西)。我编写了一个名为 Shroud 的小应用程序,它具有类似的功能 - 它隐藏一个无边框窗口,当您将鼠标移到菜单栏上时,该窗口会覆盖菜单栏。 代码足够简单,作为示例可能很有用。
You need to add a tracking area if you want to receive
mouseMoved
events (I assume that's what you mean as Cocoa has no such thing as amouseOver
event).I wrote a little app called Shroud which does something similar — it hides a borderless window which covers the menu bar when you move the mouse over it. The code is simple enough it might be useful as an example.
以下是在 @NicholasRiley 的 答案:
Here's an example written with the help of @NicholasRiley's answer: