1

我正在为 OSX 开发一个状态栏应用程序,我正在尝试复制 Dropbox 使用的弹出框的行为,到目前为止,我已经设法让所有所需的行为正常工作,除了当我打开任务时control popover 不会消失,它只是停留在任务控制的顶部覆盖部分。最近几天我一直在努力搜索,但尚未提出解决方案。我唯一能想到的可能就是让听众聆听向上 3 根手指的滑动?获得像弹出框行为这样的 Dropbox 是一件非常痛苦的事情,所以我计划在完成所有工作后将示例应用程序上传到 GitHub,以帮助人们节省一些时间来寻找解决方法!有没有人遇到过这个问题?干杯!

这是带有弹出框“MenuBarController”#import“MenuBarController.h”逻辑的类

@implementation MenuBarController
@synthesize statusItem;
@synthesize popover;
@synthesize popoverTransiencyMonitor;
-(id)init{
    self.statusItem = [[NSStatusBar systemStatusBar]     statusItemWithLength:NSVariableStatusItemLength];
    self.popover = [NSPopover new];
    popover.behavior = NSPopoverBehaviorTransient;
    return self;
}

-(void)runMenuBarItem{
    // The text that will be shown in the menu bar
    statusItem.title = @"";

    // The image that will be shown in the menu bar, a 16x16 black png works best
    statusItem.image = [NSImage imageNamed:@"redicon"];

    [statusItem setEnabled:YES];
    [statusItem setHighlightMode:YES];
    [statusItem setTarget:self];
    [statusItem setAction:@selector(togglePopover:)];

}

- (void) showPopover:(id)sender {
    MenuBarPopOverViewController * viewController = [[MenuBarPopOverViewController alloc] initWithNibName:@"MenuBarPopOverViewController" bundle:nil];
    popover.contentViewController = viewController;
    [popover showRelativeToRect:NSZeroRect ofView:(NSView *)sender preferredEdge:NSMinYEdge];

}

- (void) closePopover:(id)sender {
    [popover performClose:sender];
}


-(void)togglePopover:(id)sender{
    if(popover.shown){
        [self closePopover:sender];
    }else{
        [self showPopover:sender];
    }
    if (self.popoverTransiencyMonitor == nil) {
        self.popoverTransiencyMonitor = [NSEvent addGlobalMonitorForEventsMatchingMask:(NSLeftMouseDownMask | NSRightMouseDownMask | NSKeyUpMask) handler:^(NSEvent* event) {
            [NSEvent removeMonitor:self.popoverTransiencyMonitor];
            self.popoverTransiencyMonitor = nil;
            [self.popover close];
        }];
    }
}
@end
4

0 回答 0