开发者

Order the color panel out

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


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;
        }
    }
}


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.


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)
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜