简体   繁体   English

用户通知在Mac上打开其他NSStatusItem菜单

[英]Notification of User Opening other NSStatusItem's Menu on a Mac

I'm writing a mac app that sits in the menu bar and presents the user with a NSPanel instance when they click the status item. 我正在编写一个位于菜单栏中的mac应用程序,并在用户单击状态项时NSPanel显示NSPanel实例。 I want to hide the window whenever another status item's menu is opened. 我想在打开另一个状态项的菜单时隐藏窗口。 Right now, my panel stays open; 现在,我的小组保持开放; it looks like this: 它看起来像这样:

我的应用程序位于左侧,附加到无限状态项

I see other applications like mine close when another status item opens its menu, so I'm wonder which notification they're getting to know to disappear. 当另一个状态项打开其菜单时,我看到其他类似的应用程序关闭,所以我想知道他们知道哪些通知消失了。 I've looked into NSWindowDelegate and NSApplicationDelegate , but I don't see any notifications being generated. 我查看了NSWindowDelegateNSApplicationDelegate ,但我没有看到任何通知被生成。

Have any suggestions? 有什么建议吗?

I figured it out! 我想到了! In the awakeFromNib , I was setting the properties of my NSPanel instance. awakeFromNib ,我设置了NSPanel实例的属性。 I was using the following: 我使用以下内容:

[panel setStyleMask:panel.styleMask ^ NSTitledWindowMask];

Switching it to the following: 将其切换为以下内容:

[panel setStyleMask:(panel.styleMask ^ NSTitledWindowMask ^ NSNonactivatingPanelMask)];

Did the trick. 诀窍。 I figured it out after reading Neil Inglis' blog post on using MAAttachedWindow in a similar way. 在读完Neil Inglis关于以类似方式使用MAAttachedWindow 的博文后 ,我想通了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM