订购彩色面板

发布于 2024-12-03 20:09:10 字数 155 浏览 2 评论 0原文

我们都知道这将使颜色面板向前移动:[[NSApplication sharedApplication] orderFrontColorPanel:nil];,但是如何再次隐藏它呢?我尝试了 orderOutColorPanel:,但它不起作用。

We all know this will bring the color panel forwards: [[NSApplication sharedApplication] orderFrontColorPanel:nil];, but how to hide it again? I tried orderOutColorPanel:, but it does not work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千仐 2024-12-10 20:09:10

如有疑问,请使用暴力:

- (void)hideColorPanel {
    NSArray * wndws = [NSApp windows];
    for( NSWindow * w in wndws ){
        if( [w isKindOfClass:[NSColorPanel class]] ){
            [w orderOut:nil];
            break;
        }
    }
}

When in doubt, use brute force:

- (void)hideColorPanel {
    NSArray * wndws = [NSApp windows];
    for( NSWindow * w in wndws ){
        if( [w isKindOfClass:[NSColorPanel class]] ){
            [w orderOut:nil];
            break;
        }
    }
}
吃颗糖壮壮胆 2024-12-10 20:09:10

你是对的。 NSApplication 上没有方法可以关闭颜色面板。一旦面板显示,用户就可以控制该面板。

You are correct. There is no method on NSApplication to close the color panel. It is intended that the user will have control over the panel once it is shown.

酷到爆炸 2024-12-10 20:09:10

截至2016年,有一个方法。
在 Swift 3 中,你可以像这样切换 NSColorPanel:

func toggleColorPanel(_ sender: NSButton) {
  if /*NSColorPanel.sharedColorPanelExists() &&*/ NSColorPanel.shared().isVisible {
        NSColorPanel.shared().orderOut(self)
    } else {
        NSApplication.shared().orderFrontColorPanel(self)
    }
}

As of in 2016. There is a method.
in Swift 3, you can toggle NSColorPanel like this:

func toggleColorPanel(_ sender: NSButton) {
  if /*NSColorPanel.sharedColorPanelExists() &&*/ NSColorPanel.shared().isVisible {
        NSColorPanel.shared().orderOut(self)
    } else {
        NSApplication.shared().orderFrontColorPanel(self)
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文