当NSStatusItem被隐藏时被告知

编程入门 行业动态 更新时间:2024-10-25 18:33:47
本文介绍了当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被隐藏时被告知

本文发布于:2023-10-31 05:08:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545095.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:被告   NSStatusItem

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!