我用以下内容打开一个窗口:
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之上打开一个模式窗口吗?谢谢大家:-)
发布于 2010-03-08 14:43:28
好吧,这里有一个更好的选择--在我查看文档时完全错过了这个选项:
NSOpenPanel *OP = [NSOpenPanel openPanel];
[OP setLevel:CGShieldingWindowLevel()];
[OP beginWithCompletionHandler:^(NSInteger returnCode) {
NSLog(@"completionHandler called with %d", returnCode);
}];..。依:打开面板,就像打开自己的窗户一样,这正是我最想做的事情(嗯!)
发布于 2011-06-01 10:34:34
您可以创建这样一个类别的NSSavePanel:
@implementation NSSavePanel (SavePanelSetLevel)
- (void)setLevel:(NSInteger)newLevel
{
[super setLevel:CGShieldingWindowLevel()] ; // NSWindow implementation call
}
@end因为runModal重置了以前设置的级别!
发布于 2010-01-03 22:32:16
好的,5年后,我可以把它做好--诀窍是打开第二个窗口,把它推广到CGShieldingWindowLevel,让它键和顺序前面,然后把打开的工作表附加到它上面--工作表神奇地出现在第二个窗口的任何地方,虽然并不完美,但它看起来比我最初想出的解决方案要好得多。这是零钱:
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);
}];..。唯一需要注意的是,在下面,您可以打开几个打开的对话框,因为工作表是主窗口以外的窗口的模式-主窗口仍然可以接受鼠标单击事件.
https://stackoverflow.com/questions/1941749
复制相似问题