我有一个NSPopover
窗口,我想添加触摸栏支持。我已经设法实现了对标准的触摸栏支持NSWindow
,但是对我的弹出框执行相同的程序不会导致任何触摸栏项目出现在 xCode 触摸栏模拟器中。
我正在实施makeTouchbar
并且NSTouchBarDelegate
在NSViewController
其中呈现为NSPopover
. makeTouchBar
并且正在调用委托函数,但触摸栏中没有显示任何内容(在下面的代码块中,触摸栏和提示都在记录)。
我担心 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
}
}
}