简体   繁体   中英

Custom PKDrawing file

can you please please help me how can I create my own, custom PKDrawing file? I've watched WWDC and I see that in the code of the sample app are using PKDrawing file. I would like to create my own PKDrawing file, with lines or curves. Any tips on how to approach this?

Tried creating random json file to.drawing one, but did not work properly.

Thank you in advance for your help!

struct TextGenerator {
    let lowercaseDrawings: [PKDrawing]
    let uppercaseDrawings: [PKDrawing]

    // The number of strokes in each letter of the alphabet, for upper/lowercase assets.
    static let lowercaseStrokeCount = [1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1]
    static let uppercaseStrokeCount = [3, 2, 1, 2, 4, 3, 2, 3, 3, 2, 2, 1, 2, 2, 1, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 1]
    

You can create a new drawing by providing strokes: PKDrawing(strokes:[PKStroke])

The line and curves you want to create are the PKStrokes you provided. To create a PKStroke, you need many parameters, but the most important parameter is the PKStrokePath. PKStrokePath contains all points to form curves.

If you able to find all the points on the curve you want to create, you can create PKStrokePoint from CGPoint and from those PKStrokePoints you can create a StrokePath: PKStrokePath(points: [PKStrokePoint])

As far as I know, you must create it with an iPad, by drawing, then exporting as Data , persisting to disk as a file, and then you may rename it. I'm unaware of other ways of creating such files outside of the iPad environment, unfortunately. It looks like their "file encoding" is proprietary, so there may not be external tools that do this.

I hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM