Editing PKDrawing in PencilKit

橙三吉。 提交于 2020-07-21 05:23:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!