我有一个由6个顶点组成的UIBezierPath。现在我想从UIBezierPath获取这些顶点。有没有办法做到这一点?
答案 0 :(得分:3)
您可以使用CGPathApply
和CGPathApplierFunction
执行此操作。
NSMutableArray *thePoints = [[NSMutableArray alloc] init];
UIBezierPath *aPath;
CGPath theCGPath = aPath.CGPath;
CGPathApply(theCGPath, thePoints, MyCGPathApplierFunc);
它的作用是将Applier函数传递给每个路径的元素。您可以从函数中的每个元素中获取一个点列表,并将它们添加到thePoints
。
您的申请人功能看起来像
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.
}