Hide MAAttachedWindow when clicking outside

后端 未结 2 962
醉话见心
醉话见心 2020-12-16 08:15

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

2条回答
  •  感动是毒
    2020-12-16 08:56

    This is based on Carter Allen answer, but maybe will be helpfull to someone as i lost couple of hours trying to figure out the reason behind an EXEC_BAD_ACCESS, in short you can't release the attachedWindow inside his windowDidResignKey notification, so use autorelease:

    - (void)windowDidResignKey:(NSNotification *)aNotification {
        NSLog(@"MainWinDelegate::windowDidResignKey: %@", [aNotification object]);
    
        if (fAttachedWindow && [aNotification object] == fAttachedWindow) {
            [window removeChildWindow:fAttachedWindow];
            [fAttachedWindow orderOut:self];
            [fAttachedWindow autorelease];
            fAttachedWindow = nil;
        }
    }
    

提交回复
热议问题