我有一個NSPopover
窗口,我想添加touchbar支持。我設法實現了標準NSWindow
的觸摸板支持,但按照相同的步驟爲我的彈出窗口不會導致出現在xCode touchbar模擬器中的任何觸摸欄項目。Touchbar和NSPopover窗口
我正在執行makeTouchbar
和NSTouchBarDelegate
中的NSViewController
,它被表示爲NSPopover
。 makeTouchBar
和委託函數正在調用,但觸摸條中沒有顯示任何內容(在下面的代碼塊中,Touchbar和提示都正在記錄)。
我擔心NSPopover窗口不會觸發觸摸欄作爲活動應用程序,即使它具有鍵盤焦點。如何顯示NSPopover
窗口的觸摸條項目?
//MARK: Touch bar
@available(OSX 10.12.1, *)
override func makeTouchBar() -> NSTouchBar? {
Swift.print("Touchbar.")
let touchBar = NSTouchBar()
touchBar.delegate = self
touchBar.customizationIdentifier = .touchBar
touchBar.defaultItemIdentifiers = [.tbHint, .colourC]
return touchBar
}
@available(OSX 10.12.1, *)
extension RememberViewController: NSTouchBarDelegate {
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItemIdentifier) -> NSTouchBarItem? {
switch identifier{
case NSTouchBarItemIdentifier .tbHint:
Swift.print("hint")
let buttonView = NSCustomTouchBarItem(identifier: identifier)
let button = NSButton(title: "Hint", target: self, action: #selector(showHint))
buttonView.view = button
return buttonView
case NSTouchBarItemIdentifier .colourC:
let colorPicker: NSColorPickerTouchBarItem
colorPicker = NSColorPickerTouchBarItem.colorPicker(withIdentifier: identifier)
colorPicker.customizationLabel = "Color Picker"
colorPicker.target = self
colorPicker.action = #selector(showHint)
return colorPicker
default:
return nil
}
}
}
謝謝,但我認爲這更多的解決方法轉換爲工作表是一個完全不同的用戶體驗模型。 – RealCasually
的確,但這可以幫助其他人。由於這個想法有效,它不值得downvote ... – vomi