贝塞尔曲线在ios开发中运用的非常广泛,例如在绘画,路径的设置等非常的方便,有的时候我们如果能够得到上面的点的坐标,我们能做的事情就更多了我们可以通过下面的方法得到贝塞尔曲线上的所有的点:
#define VALUE(_INDEX_) [NSValue valueWithCGPoint:points[_INDEX_]]
@implementation UIBezierPath (Points)
void getPointsFromBezier(void *info,const CGPathElement *element){
NSMutableArray *bezierPoints = (__bridge NSMutableArray *)info;
CGPathElementType type = element->type;
CGPoint *points = element->points;
if (type != kCGPathElementCloseSubpath) {
[bezierPoints addObject:VALUE(0)];
if ((type != kCGPathElementAddLineToPoint) && (type != kCGPathElementMoveToPoint)) {
[bezierPoints addObject:VALUE(1)];
}
}
if (type == kCGPathElementAddCurveToPoint) {
[bezierPoints addObject:VALUE(2)];
}
}
- (NSArray *)points
{
NSMutableArray *points = [NSMutableArray array];
CG