Construct PKToolPicker ourselves
This commit is contained in:
parent
2fe19a5abe
commit
bbe260bc9e
|
@ -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,25 +72,19 @@ 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)
|
toolPicker.setVisible(true, forFirstResponder: canvasView)
|
||||||
|
toolPicker.addObserver(canvasView)
|
||||||
|
toolPicker.addObserver(self)
|
||||||
|
|
||||||
// todo: should the PKToolPicker be owned by this VC or something else?
|
updateLayout(for: toolPicker)
|
||||||
if let window = parent?.view.window, let toolPicker = PKToolPicker.shared(for: window) {
|
canvasView.becomeFirstResponder()
|
||||||
toolPicker.setVisible(true, forFirstResponder: canvasView)
|
|
||||||
toolPicker.addObserver(canvasView)
|
|
||||||
toolPicker.addObserver(self)
|
|
||||||
|
|
||||||
updateLayout(for: toolPicker)
|
// wait until the next run loop iteration so that the canvas view has become first responder and it's undo manager exists
|
||||||
canvasView.becomeFirstResponder()
|
DispatchQueue.main.async {
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(self.updateUndoRedoButtonState), name: .NSUndoManagerDidUndoChange, object: self.undoManager!)
|
||||||
// wait until the next run loop iteration so that the canvas view has become first responder and it's undo manager exists
|
NotificationCenter.default.addObserver(self, selector: #selector(self.updateUndoRedoButtonState), name: .NSUndoManagerDidRedoChange, object: self.undoManager!)
|
||||||
DispatchQueue.main.async {
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(self.updateUndoRedoButtonState), name: .NSUndoManagerDidUndoChange, object: self.undoManager!)
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(self.updateUndoRedoButtonState), name: .NSUndoManagerDidRedoChange, object: self.undoManager!)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue