Swift PKToolPickerObserver「指で描画」は検出出来るのか?
「指で描画」スイッチの検出目的で調査したが、「指で描画」は検出出来ない。
コード
import UIKit import PencilKit class PencilKitViewController: UIViewController { var pkcanvasview: PKCanvasView = PKCanvasView(frame: .zero) let pktoolpicker = PKToolPicker() override func viewDidLoad() { super.viewDidLoad() self.view.addSubview(self.pkcanvasview) self.pkcanvasview.isOpaque = false self.pkcanvasview.backgroundColor = .clear self.pktoolpicker.addObserver(self.pkcanvasview) self.pktoolpicker.addObserver(self) self.pktoolpicker.setVisible(true, forFirstResponder: self.pkcanvasview) self.pkcanvasview.becomeFirstResponder() self.view = self.pkcanvasview } override func viewDidAppear(_ animated: Bool) { print("width:\(self.view.frame.width) height:\(self.view.frame.height) zoomScale:\(self.pkcanvasview.zoomScale)") } } extension PencilKitViewController: PKToolPickerObserver { func toolPickerSelectedToolDidChange(_ toolPicker: PKToolPicker) { print("***** \(#function)") } func toolPickerIsRulerActiveDidChange(_ toolPicker: PKToolPicker) { print("***** \(#function)") } func toolPickerVisibilityDidChange(_ toolPicker: PKToolPicker) { print("***** \(#function)") } func toolPickerFramesObscuredDidChange(_ toolPicker: PKToolPicker) { print("***** \(#function)") } }
実行結果
生成、表示 ***** toolPickerSelectedToolDidChange(_:) ***** toolPickerVisibilityDidChange(_:) ペン種類・色変更 ***** toolPickerSelectedToolDidChange(_:) ルーラー表示・非表示 ***** toolPickerIsRulerActiveDidChange(_:)