Reputation: 3506
I have a UIBezierPath made with 6 vertices. Now I want to get those vertices from the UIBezierPath. Is there any possible way to do it?
Upvotes: 0
Views: 592
Reputation: 1937
You could do this using CGPathApply
and CGPathApplierFunction
.
NSMutableArray *thePoints = [[NSMutableArray alloc] init];
UIBezierPath *aPath;
CGPath theCGPath = aPath.CGPath;
CGPathApply(theCGPath, thePoints, MyCGPathApplierFunc);
What it does is pass on the Applier Function to each of the path's elements. You can get a list of points from each element inside your function and add them to thePoints
.
Your applier function would look something like
void MyCGPathApplierFunc (void *info, const CGPathElement *element) {
NSMutableArray *thePoints = (NSMutableArray *)info;
CGPoint *points = element->points;
[thePoints addObject:[NSValue valueWithCGPoint:points[0]]];
\\Only 1 point assuming it is a line
\\Curves may have more than one point in points array. Handle accordingly.
}
Upvotes: 3