Construct PKToolPicker ourselves

This commit is contained in:
Shadowfacts 2021-06-06 21:33:17 -04:00
parent 2fe19a5abe
commit bbe260bc9e
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 14 additions and 18 deletions

View File

@ -23,6 +23,8 @@ class ComposeDrawingViewController: UIViewController {
private(set) var undoBarButtonItem: UIBarButtonItem! private(set) var undoBarButtonItem: UIBarButtonItem!
private(set) var redoBarButtonItem: UIBarButtonItem! private(set) var redoBarButtonItem: UIBarButtonItem!
private var toolPicker: PKToolPicker!
private var initialDrawing: PKDrawing? private var initialDrawing: PKDrawing?
init() { init() {
@ -70,13 +72,8 @@ class ComposeDrawingViewController: UIViewController {
canvasView.topAnchor.constraint(equalTo: view.topAnchor), canvasView.topAnchor.constraint(equalTo: view.topAnchor),
canvasView.bottomAnchor.constraint(equalTo: view.bottomAnchor) canvasView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
]) ])
}
override func viewWillAppear(_ animated: Bool) { toolPicker = PKToolPicker()
super.viewWillAppear(animated)
// todo: should the PKToolPicker be owned by this VC or something else?
if let window = parent?.view.window, let toolPicker = PKToolPicker.shared(for: window) {
toolPicker.setVisible(true, forFirstResponder: canvasView) toolPicker.setVisible(true, forFirstResponder: canvasView)
toolPicker.addObserver(canvasView) toolPicker.addObserver(canvasView)
toolPicker.addObserver(self) toolPicker.addObserver(self)
@ -90,7 +87,6 @@ class ComposeDrawingViewController: UIViewController {
NotificationCenter.default.addObserver(self, selector: #selector(self.updateUndoRedoButtonState), name: .NSUndoManagerDidRedoChange, object: self.undoManager!) NotificationCenter.default.addObserver(self, selector: #selector(self.updateUndoRedoButtonState), name: .NSUndoManagerDidRedoChange, object: self.undoManager!)
} }
} }
}
func updateLayout(for toolPicker: PKToolPicker) { func updateLayout(for toolPicker: PKToolPicker) {
let obscuredFrame = toolPicker.frameObscured(in: view) let obscuredFrame = toolPicker.frameObscured(in: view)