Detect if menu bar is hidden or visible
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a way in Cocoa to receive a notification (or something similar) when the menu bar becomes hidden or visible? I tried looking around and have not found any information on this topic. Thanks 回答1: I solved this by using Carbon's menu event handlers. I registered for events kEventMenuBarHidden and kEventMenuBarShown under the class kEventClassMenu . 回答2: Optionally watch out for (Cocoa) notifications for an object of class NSStatusBarWindow and notifications like NSWindowDidChangeOcclusionStateNotification NSWindowWillCloseNotification