如何使窗口(osx)始终悬停在屏幕顶部

时间:2022-10-08 19:46:30

i trying to make a osx application that just have one window and it will always on the top of screen. anyone knows how to achieve it? thanks.

我试图制作一个只有一个窗口的osx应用程序,它总是在屏幕的顶部。有谁知道如何实现它?谢谢。

2 个解决方案

#1


23  

You can change the window's windowLevel (via -setLevel:) to NSFloatingWindowLevel.

您可以将窗口的windowLevel(通过-setLevel :)更改为NSFloatingWindowLevel。

[window setLevel:NSFloatingWindowLevel]; 

Documentation is here: Window_Levels

文档在这里:Window_Levels

#2


1  

By "on the top", do you mean you do not want your window to be obscured, even if a different app is active? In that case, one way is to start with the NSPanel template in Interface Builder, check the "Utility" option, and uncheck "Hide on Deactivate".

通过“在顶部”,您是否意味着您不希望您的窗口被遮挡,即使其他应用程序处于活动状态?在这种情况下,一种方法是从Interface Builder中的NSPanel模板开始,选中“Utility”选项,并取消选中“Hide on Deactivate”。

#1


23  

You can change the window's windowLevel (via -setLevel:) to NSFloatingWindowLevel.

您可以将窗口的windowLevel(通过-setLevel :)更改为NSFloatingWindowLevel。

[window setLevel:NSFloatingWindowLevel]; 

Documentation is here: Window_Levels

文档在这里:Window_Levels

#2


1  

By "on the top", do you mean you do not want your window to be obscured, even if a different app is active? In that case, one way is to start with the NSPanel template in Interface Builder, check the "Utility" option, and uncheck "Hide on Deactivate".

通过“在顶部”,您是否意味着您不希望您的窗口被遮挡,即使其他应用程序处于活动状态?在这种情况下,一种方法是从Interface Builder中的NSPanel模板开始,选中“Utility”选项,并取消选中“Hide on Deactivate”。