NSPopover以分离状态启动 [英] NSPopover to start in a detached state

查看:127
本文介绍了NSPopover以分离状态启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以强制NSPopover以分离状态启动?我只看到isDetached,它是弹出框状态的只读属性,还有NSPopoverDelegate方法detachableWindow(forPopover:),它使我可以覆盖创建的窗口.我实际上想单击一个按钮,并使NSPopover在此照片的状态下启动.

Is there a way to force the NSPopover to start in the detached state? I only see isDetached which is a read-only property for the state of the popover and an NSPopoverDelegate method detachableWindow(forPopover:) which lets me override the window that gets created. I'd like to essentially click a button and have the NSPopover start in the state in this photo.

此窗口的样式恰好是产品的要求,我似乎找不到任何NSWindow样式设置来使窗口做类似这样的事情(也没有NSPanel)

The style of this window is exactly what a product requirement is and I can't seem to find any NSWindow style settings that would make a window do something like this (nor an NSPanel)

这种独立的弹出框功能在其中似乎很特别:

This detached popover functionality seems special in that it:

  1. 非模态,但保持在主应用之上.仍然能够与主应用程序交互,就像在消息"中一样,如何仍然可以单击并键入新消息.
  2. 单击另一个应用程序AppFoo,会将主应用程序和帮助程序窗口都置于AppFoo后面.
  3. 帮助器窗口可以移动,并且在应用程序停用后不会隐藏(其他应用程序被选中).
  4. 左上角有一个小小的本机灰色X.

推荐答案

这就是诀窍. 使用所需的委托方法detachableWindowForPopover:为您完成工作,例如:

Here is the trick. Use the required delegate method detachableWindowForPopover: to do the work for you, like:

- (void) showPopoverDetached
{
    NSWindow* detachedWindow = [self detachableWindowForPopover:nil];

    [detachedWindow.windowController showWindow:nil];
}

似乎Apple工程师以一种非常聪明的方式实现了detachableWindowForPopover:,我想它使用了内容视图控制器类,并且将始终创建类似分离窗口实例的单例. 一旦detachableWindowForPopover:调用了所呈现的窗口实例,无论何时何地调用它,都将重复使用它,直接调用它(从上面的示例中的函数)或间接调用它(例如,当您拖动,分离,从其原始位置)

Seems that the Apple engineers implemented detachableWindowForPopover: on a pretty smart way, I guess it uses the content view controller class, and will always create a singleton like instance of the detached window. Once detachableWindowForPopover: has called the presented window instance will be re-used no matter when and why it is called, called it directly (from a func like my sample above) or indirectly (e.g. when you drag out, detach, the popover from its original position)

这样,它们可以防止弹出窗口两次"分离,我们还可以以编程方式实现分离的方法,这对他们来说是一件好事!

This way they can prevent a popover being detached 'twice' and we can also implement the detached way programmatically, nice job from them!

这篇关于NSPopover以分离状态启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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