NSWindow makeKeyAndOrderFront makes window appear, but not Key or Front

后端 未结 3 1823
死守一世寂寞
死守一世寂寞 2021-02-01 18:28

makeKeyAndOrderFront is not making my NSWindow key or front.

My app does not have a main window or menubar, which may be part of the proble

相关标签:
3条回答
  • 2021-02-01 19:07

    Stab in the dark: You have LSBackgroundOnly set in your Info.plist. That's what makes this not work: A background-only application cannot come to the foreground, which is why your window does not come to the foreground.

    If you want your app to not show up in the Dock, set LSUIElement instead. This suppresses your app's Dock tile and keeps it from showing its own main menu in the menu bar, but preserves its ability to bring a window frontmost and make it key.

    0 讨论(0)
  • 2021-02-01 19:08

    Try calling this method [NSApp activateIgnoringOtherApps:YES];. This should make it the active application.

    0 讨论(0)
  • 2021-02-01 19:09

    Both of these answers are correct. You'll also need to make sure you override canBecomeKey in your window subclass if it's borderless.

    This took be forever to figure out. (I wrote a blog post about the entirety of my solution.)

    0 讨论(0)
提交回复
热议问题