1

I'm working on a status bar app for OSX and I'm trying to replicate the behaviour of the popover that Dropbox uses, so far I've managed to get all of the desired behaviour working except for the fact that when I open mission control the popover doesn't fade away, it simply stays on top covering part of mission control. I've searched quite hard the last few days and have yet to come up with a solution. The only thing I could think of perhaps doing would be to have a listener listening for an upwards 3 finger swipe? Getting the dropbox like popover behaviour has been a royal pain so I plan on uploading a sample app to GitHub once I get this all working to help save people some time trying to find workarounds! Has anyone encountered this issue? Cheers!

Here is the class with the logic for the popover "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
Julian Hunt
  • 119
  • 3
  • 11
  • From what I can tell this is a bug with NSPopovers being used with NSStatusItems. My current work around is using an NSPanel instead as the transciency option seems to work with them. Though NSPopovers are much prettier this will have to do for now until Apple get's around to fixing these annoying issues! I'll post a link to a repo of this sample app once I get it completed and hopefully save some of you the hassle! – Julian Hunt May 28 '15 at 19:34

0 Answers0