简体   繁体   English

使用LSUIElement(又名Dock图标)但保留“文件,编辑,查看”菜单栏?

[英]Use LSUIElement (aka no Dock icon) but retain the “File, Edit, View” menubar?

I want my app to have: 我希望我的应用具有:

  • Menubar extra icon (by the clock) 菜单栏多余的图标(按时钟)
  • App Menubar ("File, Edit, View, Etc") 应用程序菜单栏(“文件,编辑,查看等”)

I do not want my app to have: 希望我的应用具有:

  • Dock Icon 码头图标

Is this possible? 这可能吗? I am deploying for 10.6 and 10.7 via the Mac App Store if that matters. 如果重要的话,我将通过Mac App Store部署10.6和10.7。

Setting LSUIElement in the info.plist file removes the dock icon, but it also removes the menubar. 在info.plist文件中设置LSUIElement会删除停靠图标,但也会删除菜单栏。

NSApplication's setActivationPolicy might be what you are after. 您可能需要使用NSApplication的setActivationPolicy

[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];

Please note the discussion: 请注意讨论:

Currently, NSApplicationActivationPolicyNone and NSApplicationActivationPolicyAccessory may be changed to NSApplicationActivationPolicyRegular, but other modifications are not supported.Needs links to running application 当前,NSApplicationActivationPolicyNone和NSApplicationActivationPolicyAccessory可能会更改为NSApplicationActivationPolicyRegular,但不支持其他修改。需要链接到正在运行的应用程序

As per NSApplicationActivationPolicyAccessory's documentation you may need to programmatically ensure that the menu bar appears. 根据NSApplicationActivationPolicyAccessory的文档,您可能需要以编程方式确保出现菜单栏。

You could create two "separate" applications. 您可以创建两个“单独的”应用程序。 One that has a dock icon and menu items,the other one has just the icon by the clock. 一个带有停靠图标和菜单项,另一个带有时钟图标。 When you click on the icon by the clock it launches the dock application. 当您按时钟单击图标时,它将启动停靠应用程序。 When you close the dock application the 'background' application stays running. 当您关闭停靠应用程序时,“后台”应用程序将保持运行状态。

If that model will work for you then that's the way to go. 如果该模型适合您,那就是要走的路。 But I would weigh that effort against what File-Edit-View will do for you. 但是,我将把这种努力与File-Edit-View为您所做的事情权衡。

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

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