0

行に参加しようとすると問題が発生します。ここに写真があります:

画像1

そして、私はそれが次のように見えるのが好きです:

画像2

私のコードは次のとおりです。

- (void) drawRect:(CGRect)rect {
    [super drawRect:rect];
    CGContextRef context = UIGraphicsGetCurrentContext();

    const CGFloat *components = CGColorGetComponents(self.lineColor.CGColor);

    CGFloat red;
    CGFloat green;
    CGFloat blue;
    CGFloat alpha;

    if(CGColorGetNumberOfComponents(self.lineColor.CGColor) == 2)
    {
        red   = 1;
        green = 1;
        blue  = 1;
        alpha = 1;
    }
    else
    {
        red   = components[0];
        green = components[1];
        blue  = components[2];
        alpha = components[3];
        if (alpha <= 0) alpha = 1;
    }


    // set the stroke color and width
    CGContextSetRGBStrokeColor(context, red, green, blue, alpha);
    CGContextSetLineWidth(context, 2.0);

    if (self.points.count >0) {


    BezierPoint *firstPoint = [self.points objectAtIndex:0];

    CGContextMoveToPoint(context, firstPoint.center.x, firstPoint.center.y);

    int index = 0;
    for (BezierPoint *point in self.points ) {


        if(index == 0){
            index++;
            continue;
        }

        CGContextAddLineToPoint(context, point.center.x, point.center.y);

    }

    CGContextAddLineToPoint(context, firstPoint.center.x, firstPoint.center.y);
    }


    CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.0);
    CGContextDrawPath(context, kCGPathFillStroke);

    }

私が抱えている問題は、追加するすべてのポイントに対して、線が重なるということです。滞在中に、グロブリンが重ならない幾何学的図形のポイントを追加したいと思います

誰かが私を助けることができれば、私は感謝します!!

4

2 に答える 2

0

問題を修正する簡単な方法は、最初に 2 点間に 1 つの線分のみを描画し、結果を確認することです。その後、ループを形成できます。私はあなたが完全な座標点を割り当てていないか、あなたのループが次のもので構成されている必要があると思います:

CGContextAddLineToPoint(context, point.center.x, point.center.y);

そして、CGContextMoveToPoint(context, point.center.x, point.center.y);

これは、最初に線を引いて次の点に移動することを示しています。お役に立てれば。

于 2013-07-29T17:00:40.693 に答える