当NSStatusItem被隐藏时被告知 [英] Being apprised of when NSStatusItem is hidden

查看:257
本文介绍了当NSStatusItem被隐藏时被告知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序使用 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?

到目前为止我尝试了:


  • 我检查了 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)

有关键窗口和主窗口之间区别的清楚说明,请参阅 this

For a clear explanation about the difference between a key window and a main window, see this.

这篇关于当NSStatusItem被隐藏时被告知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆