简体   繁体   English

如何使About窗口成为可可应用程序中没有UI的最前面的窗口?

[英]How do I make an About window the front-most window in a Cocoa application with no UI?

I'm building a Cocoa application that runs as an item in the status bar. 我正在构建一个可可状态栏中运行的Cocoa应用程序。 This application has an About window and an item to activate that about window, using the standard Cocoa mechanism for doing so ( -[NSApplication orderFrontStandardAboutPanel:] ). 该应用程序具有一个About窗口和一个用于激活About窗口的项目,使用标准的Cocoa机制来执行此操作( -[NSApplication orderFrontStandardAboutPanel:] )。 Naturally this is all hooked up automagically. 自然,所有这些都是自动连接的。

It works great except for one thing: unlike most About windows, it shows up underneath all other windows, rather than on top. 它除了一件事之外还很不错:与大多数“关于”窗口不同,它显示所有其他窗口的下方 ,而不是顶部。 I believe this is because the application does not have a UI, so all its windows are automatically beneath other windows. 我相信这是因为该应用程序没有UI,因此其所有窗口都自动位于其他窗口之下。 Is there a way I can hook into the NSApplication mechanism for displaying the About window so I can send it to the front, and make it respond to ⌘-W so it can be closed from the keyboard? 有没有一种方法可以挂接到NSApplication机制中以显示“关于”窗口,以便可以将其发送到前面,并使它响应⌘-W以便可以从键盘关闭它? I've poked around in the docs for NSApplication, but there's no way to get a reference to the About window that I can see so that I can make it appear on top. 我在NSApplication的文档中闲逛,但是无法获取对“可见”窗口的引用,以便使它显示在顶部。

Is there a way I can hook into the NSApplication mechanism for displaying the About window so I can send it to the front? 有没有一种方法可以挂入NSApplication机制来显示“关于”窗口,以便将其发送到前面?

That's what orderFrontStandardAboutPanel: does. 这就是orderFrontStandardAboutPanel:所做的。

It works great except for one thing: unlike most About windows, it shows up underneath all other windows, rather than on top. 它除了一件事之外还很不错:与大多数“关于”窗口不同,它显示在所有其他窗口的下方,而不是顶部。 I believe this is because the application does not have a UI, so all its windows are automatically beneath other [applications'] windows. 我相信这是因为该应用程序没有UI,所以它的所有窗口都自动位于其他[应用程序]窗口的下面。

Try bringing your application to the front with [NSApp activateIgnoringOtherApps:YES] . 尝试使用[NSApp activateIgnoringOtherApps:YES] 将应用程序置于最前面

Note that how you make your application “not have a UI” matters: If you're using LSUIElement, that will work, whereas LSBackgroundOnly pretty strictly means background- only . 请注意,如何使应用程序“不具有UI”很重要:如果使用的是LSUIElement,那将起作用,而LSBackgroundOnly严格来说表示背景。

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

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