显示模态 NSWindow,而不激活其他应用程序窗口 [英] Showing a modal NSWindow, without activating the other application windows

查看:24
本文介绍了显示模态 NSWindow,而不激活其他应用程序窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 MenuBar 中正确显示的 NSStatusItem.其中一项(单击时)显示我的应用程序中的模态 NSWindow,它旨在执行一次性任务,然后消失.(例如,用户输入一小段文字,点击保存",模态 NSWindow 消失.)

I have an NSStatusItem that is properly displaying in the MenuBar. One of the items (when clicked) displays a modal NSWindow from my application, which is meant to perform a one-off task, then disappear. (Eg. the user enters a small bit of text, clicks "Save", and the modal NSWindow goes away.)

当应用程序在后台运行时会出现此问题.模态窗口正确地出现在前台运行的任何应用程序上方,但是当用户单击保存"按钮时,应用程序的其余窗口也被激活.这是不可取的,因为用户必须单击返回到他们正在使用的任何应用程序.(破坏了 NSStatusItem 的便利性.)我正在使用以下方式显示模式窗口:

The issue occurs when the application is running in the background. The modal window properly appears above whatever application is running in the foreground, but when the user clicks the "Save" button, the rest of the application's windows also are made active. This is undesirable, as the user then has to click back to whatever app they were using. (Destroying the convenience of the NSStatusItem.) I'm displaying the modal window using:

[myWindow setFrame:finalRect display:YES animate:NO];
[myWindow setLevel:NSPopUpMenuWindowLevel];
[NSApp runModalForWindow:myWindow];

有什么方法可以防止弹出窗口中的点击/事件导致应用程序的其余部分变为活动状态?或者让 NSApp 知道这个特定面板不应该自动激活应用程序的其余部分的方法?谢谢!

Is there any way to prevent clicks/events in my popup window from causing the rest of the application to become active? Or a way to let NSApp know that this particular panel shouldn't automatically activate the rest of the app? Thanks!

推荐答案

不要创建 NSWindow,而是创建一个 NSPanel 样式为 NSNonactivatingPanelMask.然后,您可以执行通常的 makeKeyAndOrderFront:orderOut: 以根据需要显示/隐藏面板.

Instead of creating an NSWindow, create an NSPanel with the style NSNonactivatingPanelMask. You can then do the usual makeKeyAndOrderFront: and orderOut: to show/hide panel as needed.

这篇关于显示模态 NSWindow,而不激活其他应用程序窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆