【问题标题】:CGPathAddArc clockwise and anticlockwise confusionCGPathAddArc 顺时针和逆时针混淆
【发布时间】:2016-08-29 01:54:42
【问题描述】:

以下是从M_PI/2M_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);

下面是上面代码的图。

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

【问题讨论】:

    标签: ios objective-c cgcontext cgpath


    【解决方案1】:

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

    水平翻转顺时针变为逆时针,反之亦然

    您只需将clockwise 更改为NO 即可获得所需的内容

    【讨论】:

      【解决方案2】:

      你应该多注意你使用的方法。

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

      只要把最后一个参数改成NO,就可以得到你想要的,它可以控制绘制方向。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-12-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-26
        相关资源
        最近更新 更多