Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:

  • 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];
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
496 views
Welcome To Ask or Share your Answers For Others

1 Answer

It's pretty smart of you to realize that when a status item is hidden, its window will be moved into the background.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...