How to show a window without stealing focus on macOS?

限于喜欢 提交于 2019-12-03 00:45:51

I've been playing around with this a bit, and I seem to be able to produce this effect when the frontmost window is not from the same process as the frontmost application, which is what I suspect Spotlight is probably doing. I can achieve this like so:

  1. Set LSUIElement to YES in my app's Info.plist.

  2. In Interface Builder, set the window's class to NSPanel, check "Non Activating" in the Attributes Inspector, and set "isFloatingPanel" to YES in the User Defined Runtime Attributes under the Identity Inspector.

  3. During some time that some other application is in front (I just used a 5-second delay to give myself time to pop some other app to the front and select a text field), call makeKeyAndOrderFront() followed by orderFrontRegardless() on the window.

When I do this, I get the following (note the focus ring still drawn on Xcode's "Module" field):

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!