我有一个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