[英]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?有没有办法让它发生?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.