iOS 画笔轨迹优化
一 、常规画法
- (void)draw_draw:(CGPoint *)points context:(CGContextRef)context count:(NSInteger)count {
CGContextFillPath(context);
CGContextAddLines(context, points, count);//添加线
CGContextDrawPath(context, kCGPathStroke); //根据坐标绘制路径
}
二、优化方式一
static CGPoint midPointForPoints(CGPoint p1, CGPoint p2) {
return CGPointMake((p1.x + p2.x) / 2.0, (p1.y + p2.y) / 2.0);
}
- (UIBezierPath *)draw_quadCurvedPathWithPoints:(NSArray *)points {
CGPoint currentPoint = [points[0] CGPointValue];
CGPoint previousPoint = currentPoint;
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:currentPoint];
if (points.count == 2) {
CGPoint p2 = [points[1] CGPointValue];
[path addLineToPoint:p2];
return path;
}
NSIn