简体   繁体   中英

How to keep focus on NSStatusItem until toggling it again

I'm building an app the uses a NSStatusItem. I'm wanting my NSStatusItem to open when clicked and stay open until the user clicks the NSStatusItem again. As of right now, it opens the menu but the NSStatusItem loses focus when I click away from it or click on another app. I would for the NSStatusItem's menu to stay open until the user clicks to close it. Here's my code so far just to make the NSStatusItem. Thanks

-(void)awakeFromNib{
    statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
    [statusItem setMenu:statusMenu];
    [statusItem setTitle:@"Status"];
    [statusItem setHighlightMode:YES];
}

You would probably be best off implementing a custom window that opens when you click the status item rather than using a view attached to the status item's menu.

Menus have well-defined opening/closing/mouse tracking behaviour and trying to change it in a subclass will probably just be frustrating.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM