0

私は CAShapeLayer を使用してジグソー パズルを描いています。簡単な部分である線を描くこともできました。しかし、今はその楕円の一部を切り取って楕円を描きたいと思っています。私の質問は、CGPathAddEllipseInRect を使用して楕円を切り取る方法です。コード:

CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    [shapeLayer setBounds:self.bounds];
    [shapeLayer setPosition:self.center];
    [shapeLayer setFillColor:[[UIColor clearColor] CGColor]];
    [shapeLayer setStrokeColor:[[UIColor blackColor] CGColor]];
    [shapeLayer setLineWidth:3.0f];

    // Setup the path
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 10, 10);
    CGPathAddLineToPoint(path, NULL, 75,10);
    CGPathAddEllipseInRect(path, NULL, CGRectMake(75, 10, 50, 20));
    [shapeLayer setPath:path];
    CGPathRelease(path);

    [[self layer] addSublayer:shapeLayer];

ヒントをいただければ幸いです。

4

1 に答える 1

1

を使用しないでくださいCGPathAddEllipseInRect。代わりに、開始位置と終了位置を計算してCGPathAddArcToPointorを使用する必要がありCGPathAddQuadCurveToPointます。

于 2013-07-17T10:51:53.773 に答える