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'm using an MAAttachedWindow to display a custom window under a NSStatusItem in the Menubar. Everything works fine, but I can't find an easy way to hide it when the user clicks outside of the window. I want to implement this behavior because it's what the user expects.

This is the code used to display the MAAttachedWindow:

- (void)toggleAttachedWindowAtPoint:(NSPoint)pt {
    if (!self.attachedWindow) {  
        self.attachedWindow = [[MAAttachedWindow alloc] initWithView:logView
              attachedToPoint:pt 
               inWindow:nil 
                 onSide:MAPositionBottom 
                atDistance:5.0];

  [self.attachedWindow setLevel:kCGMaximumWindowLevel];
 }

 if(isVisible)
  [self.attachedWindow makeKeyAndOrderFront:self];
 else
  [self.attachedWindow orderOut];
}

This code gets triggered by an NSStatusItem with a custom view which intercepts a click on it.

See Question&Answers more detail:os

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

1 Answer

You should be able to do this via the window's delegate method:

- (void)windowDidResignKey:(NSNotification *)notification

Set yourself as the window's delegate, and implement that to call through to your toggle method.


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