#iOS14でPKToolPickerのshared(for:)がDeprecatedされている件
これまでのやり方
if let window = UIApplication.shared.windows.first {
if let toolPicker = PKToolPicker.shared(for: window) {
toolPicker.addObserver(canvasView)
toolPicker.setVisible(true, forFirstResponder: canvasView)
canvasView.becomeFirstResponder()
}
}
iOS14 でのやり方
PKToolPickerのインスタンスをmakeUIView外で宣言。
@Binding var canvasView: PKCanvasView
let toolPicker = PKToolPicker.init()
func makeUIView(context: Context) -> PKCanvasView {
self.canvasView.tool = PKInkingTool(.pen, color: .black, width: 15)
toolPicker.addObserver(canvasView)
toolPicker.setVisible(true, forFirstResponder: canvasView)
canvasView.becomeFirstResponder()
return canvasView
}