如何使“关于”窗口成为没有UI的Cocoa应用程序中的最前面的窗口? [英] How do I make an About window the front-most window in a Cocoa application with no UI?

查看:121
本文介绍了如何使“关于”窗口成为没有UI的Cocoa应用程序中的最前面的窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Cocoa应用程序,作为项目在状态栏中运行。此应用程序有一个关于窗口和一个项目来激活关于窗口,使用标准的Cocoa机制这样做( - [NSApplication orderFrontStandardAboutPanel:] )。自然地,这是自动挂接。



它的工作原理很大除了一件事:不像大多数关于窗口,它显示在所有其他窗口 ,而不是顶部。我相信这是因为应用程序没有一个UI,所以它的所有窗口都自动在其他窗口下。有没有办法我可以挂钩NSApplication机制显示关于窗口,所以我可以发送到前面,并使其响应⌘-W,以便它可以从键盘关闭?我已经在NSApplication的文档中找过了,但是没有办法获得对我可以看到的关于窗口的引用,所以我可以让它出现在顶部。


这是 orderFrontStandardAboutPanel:的用法。


它工作伟大的除了一件事:不像多数关于窗口,它显示在所有其他窗口下,而不是在顶部。我相信这是因为应用程序没有UI,所以它的所有窗口都自动在其他[应用程序]窗口下。


尝试
$ b $

b

请注意,你如何使你的应用程序没有UI很重要:如果你使用LSUIElement,这将工作,而LSBackgroundOnly相当严格意味着仅背景。


I'm building a Cocoa application that runs as an item in the status bar. This application has an About window and an item to activate that about window, using the standard Cocoa mechanism for doing so (-[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. 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? 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.

解决方案

Is there a way I can hook into the NSApplication mechanism for displaying the About window so I can send it to the front?

That's what orderFrontStandardAboutPanel: does.

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.

Try bringing your application to the front with [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的Cocoa应用程序中的最前面的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆