问题
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?
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/56721444/editing-pkdrawing-in-pencilkit