2014-02-06 96 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. 

}