为什么我无法控制从menulet调用的NSPopover窗口级别?

时间:2015-03-10 22:27:04

标签: cocoa nspopover

我是另一个试图让应用程序在popover中相对于系统状态栏menulet显示自己的人。 我正在尝试避免使用自定义类并使用基本NSPopover。

它工作正常,除了它的窗口级别 - 我无法控制它,所以我的popover出现在所有内容上:通知中心和Spot Lite,而Mission Control不会影响它。

以下是我的示例代码(来自https://github.com/efojs/statusbarPopover):

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

// Adding menulet _POP_ to status bar
self.myItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[self.myItem setAction:@selector(showPopover:)];
[self.myItem setTitle:@"_POP_"];
[self.myItem setHighlightMode:YES];
[self.myItem setTarget:self];
[self.myItem setEnabled:YES];
}

-(void) showPopover:(id)sender {

// Click POP to see Popover

NSViewController *controller = [[NSViewController alloc] initWithNibName:@"viewController" bundle:nil];
NSPopover *popover = [[NSPopover alloc] init];
[popover setContentViewController:controller];
[popover setAnimates:NO];
[popover.contentViewController.view.window setLevel:NSPopUpMenuWindowLevel];
                                                //    NSDockWindowLevel
                                                //    NSFloatingWindowLevel
                                                //    NSMainMenuWindowLevel
                                                //    NSNormalWindowLevel
                                                //    NSPopUpMenuWindowLevel
                                                //    NSScreenSaverWindowLevel
                                                //    NSStatusWindowLevel
                                                //    NSSubmenuWindowLevel
                                                //    NSTornOffMenuWindowLevel

// Showing the Popover
[popover showRelativeToRect:self.myItem.button.frame ofView:self.myItem.button preferredEdge:NSMaxYEdge];

// Run Mission Control while Popover is open to see the problem
// It neither moves as window nor disappears as panel

// If you can solve it, please mail to the.efojs@gmail.com

}

请你如此善良并帮助我理解我是否可以解决它以及如何解决?

0 个答案:

没有答案