我有主窗口和几个子窗口,我想在用户点击停靠栏图标时显示主窗口,但没有将其设为关键窗口,如果只有一个(如果没有密钥则会自动成为密钥)窗口)。
这是当前代码:
if ( fMainWinDelegate ) {
if (not [NSApp keyWindow]) {
NSLog(@"AppDelegate::applicationShouldHandleReopen [fMainWinDelegate showWindow]");
[fMainWinDelegate showWindow];
}
else {
if ([fMainWinDelegate.window isMiniaturized]) {
NSLog(@"AppDelegate::applicationShouldHandleReopen [fMainWinDelegate.window deminiaturize:self]");
[fMainWinDelegate.window deminiaturize:self];
//this one is not working, it make window also the key window
}
else if (not [fMainWinDelegate.window isVisible] && not [fMainWinDelegate.window isMiniaturized]) {
NSLog(@"AppDelegate::applicationShouldHandleReopen [fMainWinDelegate.window orderFront:self]");
[fMainWinDelegate.window orderFront:self];
}
}
}
答案 0 :(得分:0)
我以非常简单的解决方案结束了:
if ( fMainWinDelegate ) {
if (not [NSApp keyWindow]) {
NSLog(@"AppDelegate::applicationShouldHandleReopen [fMainWinDelegate showWindow]");
[fMainWinDelegate showWindow];
}
else {
if ([fMainWinDelegate.window isMiniaturized]) {
NSLog(@"AppDelegate::applicationShouldHandleReopen [fMainWinDelegate.window deminiaturize:self]");
// save current key window
NSWindow *currKey = [NSApp keyWindow];
[fMainWinDelegate.window deminiaturize:self];
// restore saved key window
[currKey makeKeyWindow];
}
else if (not [fMainWinDelegate.window isVisible] && not [fMainWinDelegate.window isMiniaturized]) {
NSLog(@"AppDelegate::applicationShouldHandleReopen [fMainWinDelegate.window orderFront:self]");
[fMainWinDelegate.window orderFront:self];
}
}
}