How to use CGPathApply properly

前端 未结 1 1364
攒了一身酷
攒了一身酷 2021-02-08 12:55

I\'m trying to use CGPathApply to iterate over each CGPathElement in a CGPathRef object (mainly to write a custom way to persist CGPath data). The problem is, each time it get

相关标签:
1条回答
  • 2021-02-08 13:12

    element->points is a C array of CGPoint's, you can't print it out with that format specifier.

    The trouble is, there's no way to tell how many elements that array holds (none that I can think of anyway). So you'll have to guess based on the type of operation, but most of them take a single point as an argument (CGPathAddLineToPoint, for example).

    So a proper way to print it out would be

    CGPoint pointArg = element->points[0];
    NSLog(@"Type: %@ || Point: %@", element->type, NSStringFromCGPoint(pointArg));
    

    for a path operation that takes a single point as an argument.

    Hope that helps!

    0 讨论(0)
提交回复
热议问题