这两种都可以用来画线,前一种将整条线加入后画出,后一种对每个点进行和前一个点的连线。
-(void)drawLine:(YJLines *)line{
int count = [line.points count];
CGPoint addLines[count];
for (int j=0; j< [line.points count]; j++)
{
CGPoint point = CGPointFromString((NSString *)[line.points objectAtIndex:j]);
addLines[j].x = point.x;
addLines[j].y = point.y;
}
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineCap(context , kCGLineCapRound);
CGContextSetBlendMode(context, kCGBlendModeNormal);
CGContextBeginPath(context);
CGContextAddLines(context, addLines, count);
CGContextSetLineWidth(context, line.lineWidth);
CGContextSetAlpha(context, line.lineAlpha);
CGContextSetStrokeColorWithColor(context, line.lineColor.CGColor);
CGContextStrokePath(context);
}
- (void) contextDrawFrom: (CGPoint)last toPoint:(CGPoint)current withLine:(YJLines *)ln {
CGContextRef context = UIGraphicsGetCurrentContext();
// CGContextSetMiterLimit(context, 0.5);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineCap(context , kCGLineCapRound);
CGContextSetBlendMode(context, kCGBlendModeNormal);
CGContextBeginPath(context);
CGContextMoveToPoint(context, last.x, last.y);
CGContextAddLineToPoint(context, current.x, current.y);
CGContextSetLineWidth(context, ln.lineWidth);
CGContextSetAlpha(context, ln.lineAlpha);
CGContextSetStrokeColorWithColor(context, ln.lineColor.CGColor);
CGContextStrokePath(context);
}
而AddLineToPoint却会导致透明度重叠,且move touch的点出也会出现透明度重叠,会显示成点和点之间透明度正确,点上不透明的问题。
http://www.cnblogs.com/pengyingh/articles/2403225.html