Allow views in childWindow to become key without losing focus on parentWindow

牧云@^-^@ 提交于 2019-12-03 15:24:30

I got this working by mimicking the behaviour of NSPopover. On investigation I found that a popover (which uses a private NSPanel subclass "_NSPopoverWindow") believed it was the key & main window, even though it is not the window returned from [NSApp keyWindow].

Create your own custom NSPanel subclass, attach it to the parent window, and then override the following methods as so:

- (BOOL)isKeyWindow {
    return YES;
}

- (BOOL)isMainWindow {
    return YES;
}

- (BOOL)canBecomeKeyWindow {
    return YES;
}

- (BOOL)canBecomeMainWindow {
    return YES;
}

- (void)makeKeyWindow {
    [super makeKeyWindow];
    [self.parentWindow makeKeyWindow];
}
- (void)makeMainWindow {
    [super makeMainWindow];
    [self.parentWindow makeMainWindow];
}
- (void)becomeKeyWindow {
    [super becomeKeyWindow];
}

- (void)becomeMainWindow {
    [super becomeMainWindow];
    [self.parentWindow becomeMainWindow];
}

- (void)resignMainWindow {

}
- (void)resignKeyWindow {

}

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