CGPathAddArc顺时针和逆时针混淆

时间:2016-08-29 01:54:43

标签: ios objective-c cgcontext cgpath

以下是将弧从M_PI/2绘制到M_PI的代码。

CGContextRef contet=UIGraphicsGetCurrentContext();

CGMutablePathRef path = CGPathCreateMutable();
CGPathAddArc(path, NULL, CGRectGetMidX(rect), CGRectGetMidY(rect), CGRectGetMidX(rect),  M_PI/2.0,M_PI, YES);

CGContextAddPath(contet, path);
CGContextSetStrokeColorWithColor(contet, [UIColor redColor].CGColor);
CGContextStrokePath(content);

以下是上述代码的图示。

enter image description here

我期待它将它画在空的或缺失的部分,顺时针方向。我提到了这个答案Why does giving addArcWithCenter a startAngle of 0 degrees make it start at 90 degrees?但是,我不知道我错在哪里。

2 个答案:

答案 0 :(得分:0)

您应该更加关注您使用的方法。

CGPathAddArc(path, NULL, CGRectGetMidX(rect), CGRectGetMidY(rect), CGRectGetMidX(rect),  M_PI/2.0,M_PI, NO);

只需将最后一个参数更改为NO,即可获得所需内容,它可以控制绘图方向。

答案 1 :(得分:0)

因为,在Core Graphics中,原点位于左/下

水平翻转顺时针方向改为逆时针方向,反之亦然

您只需将NO更改为{{1}}即可获得所需内容