objective-c - 如何使“关于”窗口成为没有 UI 的 Cocoa 应用程序中最前面的窗口?

标签 objective-c cocoa

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

除了一件事,它工作得很好:与大多数“关于”窗口不同,它显示在所有其他窗口的下方,而不是在顶部。我相信这是因为该应用程序没有 UI,所以它的所有窗口都自动位于其他窗口下方。有没有一种方法可以连接到 NSApplication 机制来显示关于窗口,这样我就可以将它发送到前面,并让它响应 ⌘-W 以便可以从键盘关闭它?我已经查看了 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?

这就是 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.

尝试 bringing your application to the front使用 [NSApp activateIgnoringOtherApps:YES]

请注意,如何让您的应用程序“没有 UI”很重要:如果您使用的是 LSUIElement,那会起作用,而 LSBackgroundOnly 非常严格地意味着背景。

关于objective-c - 如何使“关于”窗口成为没有 UI 的 Cocoa 应用程序中最前面的窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2706563/

相关文章:

iphone - 如何等待 webViewDidFinishLoad 完成

objective-c - 为什么 %@ 在 predicateWithFormat 和 stringWithFormat 之间表现不同?

swift - 如何在 NSView 中旋转文本? (Mac 操作系统、 cocoa 、 swift )

cocoa - NSWindow 尝试关闭时显示警报

macos - NSOUlineView 标题单元格字体

objective-c - 将左下角原点位置转换为左上角原点位置(反之亦然)

iOS - 如何摆脱 "app is using your location"通知

iphone - 我如何获得 GameKit 回合制比赛的通知?

objective-c - 从AppDelegate访问其他Class实例

ios - 申请因缺乏 IPv6 支持而被拒绝