2014-02-06 55 views

回答

3

您可以使用CGPathApplyCGPathApplierFunction来做到这一点。

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. 

}