关于 PencilKit 的 iOS14
About iOS14 of PencilKit
环境
・MacOS:10.15.7
・Xcode:12.1
・iOS: 14.1
我正在尝试使用 PencilKit,但无法显示 PKToolPicker。我将我的代码设置如下:
if let window = UIApplication.shared.windows.first {
if let toolPicker = PKToolPicker.shared(for: window) {
toolPicker.addObserver(canvas)
toolPicker.setVisible(true, forFirstResponder: canvas)
canvas.becomeFirstResponder()
}
}
我在这里收到警告:
'shared(for:)' was deprecated in iOS 14.0: Create individual instances instead.
所以我改成了这样
let toolPicker = PKToolPicker.init()
toolPicker.addObserver(canvas)
toolPicker.setVisible(true, forFirstResponder: canvas)
canvas.becomeFirstResponder()
毕竟PKToolPicker不显示
我的目标是显示这样的 PKToolPicker
请多多指教
我是这样解决的
toolPicker.addObserver(canvas)
toolPicker.setVisible(true, forFirstResponder: canvas)
canvas.becomeFirstResponder()
首先在class级别为ViewController声明一个单独的toolPicker实例。这是能够在 toolPicker 中更改笔所必需的:
let toolPicker = PKToolPicker()
然后稍后,在 viewWillAppear(_ :)
toolPicker.addObserver(canvas)
toolPicker.setVisible(true, forFirstResponder: canvas)
canvas.becomeFirstResponder()
环境 ・MacOS:10.15.7 ・Xcode:12.1 ・iOS: 14.1
我正在尝试使用 PencilKit,但无法显示 PKToolPicker。我将我的代码设置如下:
if let window = UIApplication.shared.windows.first {
if let toolPicker = PKToolPicker.shared(for: window) {
toolPicker.addObserver(canvas)
toolPicker.setVisible(true, forFirstResponder: canvas)
canvas.becomeFirstResponder()
}
}
我在这里收到警告:
'shared(for:)' was deprecated in iOS 14.0: Create individual instances instead.
所以我改成了这样
let toolPicker = PKToolPicker.init()
toolPicker.addObserver(canvas)
toolPicker.setVisible(true, forFirstResponder: canvas)
canvas.becomeFirstResponder()
毕竟PKToolPicker不显示
我的目标是显示这样的 PKToolPicker
请多多指教
我是这样解决的
toolPicker.addObserver(canvas)
toolPicker.setVisible(true, forFirstResponder: canvas)
canvas.becomeFirstResponder()
首先在class级别为ViewController声明一个单独的toolPicker实例。这是能够在 toolPicker 中更改笔所必需的:
let toolPicker = PKToolPicker()
然后稍后,在 viewWillAppear(_ :)
toolPicker.addObserver(canvas)
toolPicker.setVisible(true, forFirstResponder: canvas)
canvas.becomeFirstResponder()