NSTouchBar for Sheet窗口以模态显示

时间:2018-10-20 07:09:13

标签: swift4.2 nstouchbar

我在主应用程序窗口中(以编程方式创建)TouchBar可以正常工作。我确实从主菜单中打开工作表窗口,并希望为其自定义TouchBar。代码位于其ViewController中,并且实际上已执行,但TouchBar上未显示任何内容。我应该以某种方式引用在主窗口中创建的TouchBar吗?

这是我在ViewController中显示的一些代码,如模式​​表所示:

 @available(OSX 10.12.2, *)
override func makeTouchBar() -> NSTouchBar? {
    let touchBar = NSTouchBar()
    touchBar.customizationIdentifier =  NSTouchBar.CustomizationIdentifier("com.dalon.Cipher1")
    touchBar.delegate = self
    touchBar.defaultItemIdentifiers = [.saveButton, .closeButton]
    touchBar.customizationAllowedItemIdentifiers = [.saveButton, .closeButton]
    touchBar.customizationRequiredItemIdentifiers = [.saveButton, .closeButton]
    return touchBar
}

@available(OSX 10.12.2, *)
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
    switch identifier {
    case NSTouchBarItem.Identifier.saveButton:
        let button = NSButton(title: "Save", target: self, action: #selector(save))
        let customTouchBarItem = NSCustomTouchBarItem(identifier: identifier)
        customTouchBarItem.view = button
        return customTouchBarItem
    case NSTouchBarItem.Identifier.closeButton:
        let button = NSButton(title: "Cancel", target: self, action: #selector(cancel))
        let customTouchBarItem = NSCustomTouchBarItem(identifier: identifier)
        customTouchBarItem.view = button
        return customTouchBarItem
    default:
        return nil
    }

如果我愿意

print(touchBar?.defaultItemIdentifiers)

它向我显示了我期望的两个TouchBar按钮,但它们没有显示在TouchBar上。 谢谢。

0 个答案:

没有答案