被告知何时隐藏 NSStatusItem [英] Being apprised of when NSStatusItem is hidden
问题描述
我有一个使用 NSStatusItem
的应用程序.在小屏幕上,状态栏没有太多空间.当用户切换到具有大量菜单项的应用程序时,我的状态项会被隐藏.有没有办法得到通知?
I have an app which uses an NSStatusItem
. On small screens there's not much space in the status bar. When a user switches to an application with a lot of menu items, my status item gets hidden. Is there a way to get notified about this?
到目前为止我尝试过的:
What I tried so far:
- 我检查了是否有任何
NSNotification
被触发:否 - 我检查了
statusView
是否从视图层次结构中删除:否 - 我检查了
isHiddenOrHasHiddenAncestor
:否
- I checked if any
NSNotification
is fired: No - I checked if the
statusView
is removed from the view hierarchy: No - I checked
isHiddenOrHasHiddenAncestor
: No
这是我用来创建状态项的代码.
Here's the code I use to create the status item.
self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
MyStatusView *maView = [[[MyStatusView alloc] initWithFrame:CGRectMake(0, 0, 50, 22)] autorelease];
[statusItem setTitle:@"Ma Status Item"];
[statusItem setView:maView];
推荐答案
你很聪明地意识到,当一个状态项被隐藏时,它的窗口将被移到背景中.
It's pretty smart of you to realize that when a status item is hidden, its window will be moved into the background.
现在您要查找的通知是:NSWindowDidResignKeyNotification(或 NSWindowDidResignMainNotification 取决于您的应用程序的上下文)
Now the notification you're looking for is: NSWindowDidResignKeyNotification (or NSWindowDidResignMainNotification depending on the context of your application)
关于键窗口和主窗口区别的清晰解释,参见这个.
For a clear explanation about the difference between a key window and a main window, see this.
这篇关于被告知何时隐藏 NSStatusItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!