I have a PKCanvasView setup as follows:
class PencilKitVC: UIViewController {
// MARK: - Views
private let canvasView = PKCanvasView()
private let toolPicker = PKToolPicker()
// MARK: - View Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
setupViews()
}
// MARK: - Setup
private func setupViews() {
view.backgroundColor = .lightGray
canvasView.backgroundColor = .white
// Support finger and pencil
canvasView.drawingPolicy = .anyInput
view.addSubview(canvasView)
canvasView.snp.makeConstraints {
$0.leading.trailing.top.equalToSuperview().inset(16.0)
$0.bottom.equalTo(view.safeAreaLayoutGuide).inset(16.0)
}
canvasView.minimumZoomScale = 0.5
canvasView.maximumZoomScale = 4.0
toolPicker.setVisible(true, forFirstResponder: canvasView)
toolPicker.addObserver(canvasView)
canvasView.becomeFirstResponder()
let canvasButton = UIButton()
canvasButton.setTitle("Canvas", for: .normal)
canvasButton.setTitleColor(.blue, for: .normal)
view.addSubview(canvasButton)
canvasButton.snp.makeConstraints {
$0.leading.top.equalToSuperview().inset(32.0)
}
}
}
Zooming works however I cannot pan. How can I enable panning?
Try adding following in your code : -
Hope this helps you.