我打开一个窗口,其中包含以下内容:
NSRect screenRect = [[NSScreen mainScreen] frame];
[super initWithContentRect:screenRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
int windowLevel = CGShieldingWindowLevel();
[self setLevel:windowLevel];
...所以窗口全屏&高于所有其他窗口级别(包括模态窗口)。我后来想要显示一个打开的面板,但是下面打开了我在上面创建的窗口下面的对象(似乎runModal的东西会覆盖我尝试设置的请求的窗口级别):
NSOpenPanel *OP = [NSOpenPanel openPanel];
int windowLevel = CGShieldingWindowLevel();
[OP setLevel:windowLevel];
int returnCode = [OP runModal];
...以下打开上面创建的窗口(好),但它也会显示我之前隐藏的菜单栏(不是我想要的):
NSOpenPanel *OP = [NSOpenPanel openPanel];
[OP beginSheetModalForWindow:[self window]
completionHandler:^(NSInteger returnCode) {
NSLog(@"completionHandler called with %d", returnCode);
}];
...所以我的问题是:
CGShieldingWindowLevel
上面的模态窗口?谢谢大家: - )
答案 0 :(得分:3)
好的,这是一个更好的选择 - 在我审阅文档时完全错过了这个:
NSOpenPanel *OP = [NSOpenPanel openPanel];
[OP setLevel:CGShieldingWindowLevel()];
[OP beginWithCompletionHandler:^(NSInteger returnCode) {
NSLog(@"completionHandler called with %d", returnCode);
}];
... ie:打开面板,就像它自己的窗口一样,这正是我想要做的第一个地方(呃!)
答案 1 :(得分:3)
您可以像这样创建一个NSSavePanel类别:
@implementation NSSavePanel (SavePanelSetLevel)
- (void)setLevel:(NSInteger)newLevel
{
[super setLevel:CGShieldingWindowLevel()] ; // NSWindow implementation call
}
@end
因为runModal重置了先前设置的级别!
答案 2 :(得分:2)
NSOpenPanel *OP = [NSOpenPanel openPanel];
// this is the new bit - make the window 1x1 @ the location of your liking
NSRect windowRect = NSMakeRect(0, 1000, 1, 1);
NSWindow *OPW = [[NSWindow alloc] initWithContentRect:windowRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
int windowLevel = CGShieldingWindowLevel();
[OPW setLevel:windowLevel];
[OPW makeKeyAndOrderFront:nil];
// end of new bit, apart from passing OPW for beginSheetModalForWindow
// instead of [self window]
[OP beginSheetModalForWindow:OPW
completionHandler:^(NSInteger returnCode) {
NSLog(@"completionHandler called with %d", returnCode);
}];
...唯一需要注意的是,下面你可以打开几个打开的对话框,因为工作表是主窗口以外的窗口的模态 - 主窗口仍然可以接受鼠标点击事件......