简体   繁体   English

仅当 App 处于活动状态时才显示 NSStatusItem 菜单

[英]Show NSStatusItem menu only if App is active

I'm using this method to show the NSStatusItem menu only if application is Active.仅当应用程序处于活动状态时,我才使用此方法显示 NSStatusItem 菜单。

-(void)menuWillOpen:(NSMenu*)menu{  
    if(![NSApp isActive]){
        [menu cancelTracking];
    }
    [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
    [window makeKeyAndOrderFront:self]; 
}

It perfectly works, but cancelTracking seems to block the blue highlight of the NSStatusItem.它完美地工作,但 cancelTracking 似乎阻止了 NSStatusItem 的蓝色突出显示。 So when i click on status menu item it doesn't show the submenu and it presents the main window, but the icon is not highlighted.因此,当我单击状态菜单项时,它不会显示子菜单,而是显示主 window,但图标未突出显示。 Is there a way to make it happen?有没有办法让它发生?

I suggest creating a custom view if you need more precise control over when the status item highlights itself.如果您需要更精确地控制状态项何时突出显示,我建议创建自定义视图。 Then you can use mouseDown: etc. This is a good example of putting your custom view in a status item.然后您可以使用mouseDown:等。 是将自定义视图放入状态项的一个很好的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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