1

我有以下问题:

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetLineCap(context,kCGLineCapRound);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetRGBFillColor(context, 1, 0, 0, 1);

for (drawnCurve *line in completeLines) {
CGContextBeginPath(context);    
    for(int i=0;i<[line.points count]-1;i++) 
    { 
    drawnPoint*point=[line.points objectAtIndex:i];
    drawnPoint*point2=[line.points objectAtIndex:i+1];

   // CGContextSetLineWidth(context, point.r);
    [point.color set];
    CGContextMoveToPoint(context, point.x,point.y);
        CGContextAddLineToPoint(context, point2.x, point2.y);  
    // CGContextAddCurveToPoint(context, (point.x+point2.x)/2, point2.y, (point.x+point2.x)/2, point2.y, point2.x, point2.y);

        //CGContextEOFillPath(context);
    }
    CGContextClosePath(context);
    CGContextFillPath(context);
}

但它只是消失了,没有显示任何填充曲线。有什么问题?

4

1 回答 1

1

调用CGContextMoveToPoint开始一个新的子路径。您应该在嵌套for循环之前调用它一次,然后仅CGContextAddLineToPoint用于保持线路连接:

drawnPoint*pointZero=[line.points objectAtIndex:0];
CGContextMoveToPoint(context, pointZero.x,pointZero.y);
for(int i=1;i<[line.points count];i++) 
{ 
    drawnPoint*point=[line.points objectAtIndex:i];
    CGContextAddLineToPoint(context, point.x, point.y);  
}
CGContextClosePath(context);
CGContextFillPath(context);
于 2012-08-06T19:02:31.367 回答