How to show the touchpad in the view manager

I want to develop a touchpad application. I searched the Internet and saw some lessons. They all make a demonstration using the windowcontroller and simply redefine makeTouchBar()or drag the touch panel in the storyboard, then there is a touch panel. But I want the viewbar in the control panel to be different. Then I put on the touch panel in the viewcontroller in the storyboard and tied the control panel in the viewcontroller.

enter image description here

bind(#keyPath(touchBar), to: self, withKeyPath: #keyPath(touchBar), options: nil)

But when I start the project, I can’t find my touch panel, and then type touchbar.isVisible, and I found that the value is false.

image description here

So, how to show the control panel in the viewcontroller. Thank!

+4
source share
2

ViewController, :

override func viewDidAppear() {
        super.viewDidAppear()
        self.view.window?.unbind(#keyPath(touchBar)) // unbind first
        self.view.window?.bind(#keyPath(touchBar), to: self, withKeyPath: #keyPath(touchBar), options: nil)
}
+2

.

NSTouchBar , :

  • Windows
  • Windows

, .

, viwController, touchBar .

 deinit {
        self.view.window?.unbind(#keyPath(touchBar))
    }

    override func viewDidAppear() {
        super.viewDidAppear()
        if #available(OSX 10.12.1, *) {
           self.view.window?.unbind(#keyPath(touchBar)) // unbind first
           self.view.window?.bind(#keyPath(touchBar), to: self, withKeyPath: #keyPath(touchBar), options: nil)
        }
    }

:

NSTouchBar

WWDC → nstouchbar .

+1
source

Source: https://habr.com/ru/post/1670282/


All Articles