NSWindow - show new window that will always stay on top of current window

半世苍凉 提交于 2019-11-30 05:21:37

问题


I want my NSWindow to show new window(s) that will always be on top of current window. they should NOT be on top of other windows.

In addition, they should not move when the original window moves.

How can i do that?


回答1:


Use NSWindow's addChildWindow:ordered: or setParentWindow: method to add the other window as a child of the first window. That window will follow the first window around. See the NSWindow Class Reference.




回答2:


You can set window level to NSFloatingWindowLevel so it always be on top.
To prevent window from covering other applications you can set its level to NSNormalWindowLevel or you can hide it at all. Try to use applicationWillResignActive: method (NSApplicationDelegate Protocol) to remove your window from top. To catch the moment when you shoud bring your window back on top use applicationWillBecomeActive: method.




回答3:


This worked for me, hope that will be helpful

[self.window makeKeyAndOrderFront:nil];
[self.window setLevel:NSStatusWindowLevel];


来源:https://stackoverflow.com/questions/6723578/nswindow-show-new-window-that-will-always-stay-on-top-of-current-window

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