Hide MAAttachedWindow when clicking outside

最后都变了- 提交于 2019-11-29 02:44:15

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.

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;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!