CGPoint midPoint(CGPoint p1, CGPoint p2)
{
return CGPointMake((p1.x + p2.x) * 0.5, (p1.y + p2.y) * 0.5);
}
CGContextRef contextRef;
CGPoint point1;//起始点
CGPoint point2;//结束点
CGPoint currentPoint;//当前点
- (void)DrawWithPoint:(CGPoint)point{
point1 = point2;//起点
point2 = currentPoint;//终点
currentPoint = point;//当前点
CGPoint mid1 = midPoint(point2, point1);//起点控制点
CGPoint mid2 = midPoint(point, point2);//终点控制点
contextRef = UIGraphicsGetCurrentContext();
CGContextSetAllowsAntialiasing(contextRef, YES);
CGContextSetShouldAntialias(contextRef, YES);
CGContextSetLineCap(contextRef, kCGLineCapRound);
CGContextBeginPath(contextRef);
CGContextSetLineWidth(contextRef, _linewidth);//绘制宽度
CGContextSetStrokeColorWithColor( contextRef, _linecolor.CGColor);//绘制颜色
CGContextSetShadowWithColor(contextRef, CGSizeMake(0.5, 0.5), 0.5f,_linecolor.CGColor);//阴影效果
CGContextMoveToPoint(contextRef, mid1.x, mid1.y);//绘制起点
CGContextAddQuadCurveToPoint(contextRef, point2.x, point2.y, mid2.x, mid2.y);//绘制终点
CGContextStrokePath(contextRef);
drawImage = UIGraphicsGetImageFromCurrentImageContext();
drawImageView.image = drawImage;
}