When using PencilKit in iOS 13/iPadOS, how do you change the content in PKDrawing? For example, can I go through all the lines and change the color or width of the lines? Or for selected lines (via lasso)? Or add a straight line in our own code?
PKDrawing is listed as an Opaque data object. See this Wikipedia Link for an explanation of opaque data object. Unfortunately strokes are not exposed to us. Our only 2 options currently can be found in the docs under Modifying the Drawing. Basically we can only apply a transform or append drawings in the current api. In Apple's Demo, they show how to implement undo using the append method. If you download the demo, see func setNewDrawingUndoable(_ newDrawing: PKDrawing) to see how you can implement undo.
You can set the built-in selectors undo: and redo: to the first responder of the View Controller.
WWDC 19 has a demo has an example that does that in the storyboard itself. Here's the link for you: https://developer.apple.com/documentation/pencilkit/drawing_with_pencilkit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With