订购颜色面板

时间:2011-09-07 19:31:10

标签: objective-c macos cocoa panel

我们都知道这将带来前面的颜色面板:[[NSApplication sharedApplication] orderFrontColorPanel:nil];,但如何再次隐藏它?我试过了orderOutColorPanel:,但它不起作用。

3 个答案:

答案 0 :(得分:2)

如有疑问,请使用蛮力:

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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

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