开发者

set NSWindow focused

I have an app winth one window and one panel, attached to this window.

steps:

  1. deactivate my app (app opened, but without the focus)
  2. click on a button on panel (panel is focused now, but main window is not)

How to set focus to the main window 开发者_如何学运维(parent window) from the panel?


Swift 5 version of @BUDDAx2 answer:

NSApplication.shared.activate(ignoringOtherApps: true)


It is not clear what you mean by focus, and whether what you call main window is a main window as defined in Cocoa. Assuming it is a Cocoa main window and focus is the same as key status,

[[NSApp mainWindow] makeKeyWindow];

or

[[NSApp mainWindow] makeKeyAndOrderFront:self];

If it is not a Cocoa main window, you need to have a reference to it and send it -makeKeyWindow or -makeKeyAndOrderFront:.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜