使窗口位于应用程序的最顶层
在我的应用程序中,我有一组窗口。我希望当应用程序处于活动状态时,其中一个窗口始终位于最顶层。我尝试通过更改窗口的级别来做到这一点,但没有成功。
如果我放置 NSNormalWindowLevel ,那么在单击应用程序的任何其他窗口时,该窗口将进入后台。而如果我使用除 NSNormalWindowLevel 之外的任何其他级别,则即使我切换到其他应用程序,该窗口仍保持在最上面。我希望只有当我的应用程序处于活动状态时窗口才位于最上面。如何在可可中执行此操作?
谢谢
In my application,I have a set of windows.I want one of the window to be top most all the time when the application is active.I tried doing this by changing the level of the window, but didn't succeed.
If I put NSNormalWindowLevel , then on clicking any other window of my application this window goes in background.While if I use any other level than NSNormalWindowLevel , then the window remains topmost even if I switch to some other application. I want the window to be topmost only when my application is active.How to do this in cocoa ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是可能的,但只能以编程方式完成(这意味着不能在 Interface Builder 中):
如果您有一个窗口,则使用
如果您使用窗口控制器(NSWindowController),则
一般情况下您可以使用以下级别:
如果您想要在 Interfacebuilder 中显示一个最顶层的窗口(即从菜单中调用),请在您的 App-Delegate 中创建一个 IBAction 并将调用分配给此操作:
如果您希望窗口仅在应用程序处于活动状态时位于最顶层,您可以了解您的应用程序是否处于活动状态。在“main.xib”中观察“First Responder”中的“actions”。您可以使用以下事件来重置窗口级别:“deminiaturize”、“order Front”、“order Back”等等。
希望这有帮助。玩得开心!
This is possible, but can be only done programatically (that means not in Interface Builder):
if you have a window, use
if you use a window controller (NSWindowController), use
in general you may use on of the following levels:
If you would like to show a window topmost from Interfacebuilder (i.e. a call from the menu), create a IBAction in your App-Delegate and assign the call to this action:
If you want the window being topmost only when your application is active, you have to know if your application is active. In your "main.xib" watch into the "actions" from "First Responder". You can use the following events to reset your windowlevels: "deminiaturize", "order Front", "order Back" and a lot more.
Hope this helps. Have fun!
我最终做到了这一点,通过使用函数 setHidesonDeactivate 并使用窗口的 NSFloatingWindowLevel 在应用程序停用时隐藏 NSWindow。
I did this finally , by hiding the NSWindow when the application is deactivated by using function setHidesonDeactivate and using a NSFloatingWindowLevel for the window.
复制/粘贴代码(查看deovrat singh答案)
code for copy/paste (look deovrat singh answer)
OS X 窗口系统中实际上不存在“应用程序最顶层”这样的概念。应用程序没有自己的级别。完成听起来像您想要的事情的正常方法是拥有一个浮动面板,当应用程序处于非活动状态时该面板会消失(请参阅 NSPanel 的
setFloatingPanel:
)。否则,您就必须自己切换窗位。There is not really any such concept as "topmost within an application" in the OS X windowing system. An application does not have a level of its own. The normal way to do what it sounds like you want is to have a floating panel that disappears when the application is inactive (see NSPanel's
setFloatingPanel:
). Otherwise, you'd have to switch its window level around yourself.