Reputation: 109
I successfully created PKCanvasView in my view and make it work to draw in there. But how to disable drawing in PKCanvasView for some purposes like viewing mode only.
Is it possible to disable drawing with both pencil and finger in PKCanvasView?
I can disable finger drawing with just setting the variable allowsFingerDrawing false, but I want to disable pencil too.
Upvotes: 4
Views: 2768
Reputation: 131
The solution - canvasView.isUserInteractionEnabled = false
- will also disable the scrolling features of the canvaseView.
A better solution could simply disable the drawing gesture
self.canvasView.drawingGestureRecognizer.isEnabled = false
This will turn off both pen and finger drawing but keep the scroll view features available.
Upvotes: 6
Reputation: 6059
Applies to iOS 13 and iOS 14
To answer your question, iOS 14's drawingPolicy did not provide a 'noInput' option. But an easy alternative would be to set isUserInteractionEnabled.
For example, a PKCanvasView that is declared as canvasView could be set with isUserInteractionEnabled to restrict all input:
canvasView.isUserInteractionEnabled = false
When the user is in pencil-only mode, this will also restrict the finger's long-press from inserting white space, cutting, copying, deleting, and duplicating.
Setting isUserInteractionEnabled will also restrict the two-finger scrolling on the canvas.
Upvotes: 3
Reputation: 1525
If you access the PKDrawing on the PKCanvasView you can call "imageFromRect" - This will return a UIImage that you can place on the screen for viewing without it being editable.
Upvotes: 0