1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Swift] PKToolPicker in iOS14

Posted at

#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
}

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?