在CoreGraphics中,是否有可能像SVG路径一样绘制椭圆弧?如果可以,具体如何实现?
今晚我也遇到了同样的问题。CG没有提供一种简单的方法来绘制非圆弧,但是您可以使用CGPath和适当的变换矩阵来完成它。假设您想要一个轴对齐椭圆的弧线,起点在左上角,大小为宽度,高度,则可以按如下方式操作:
CGFloat cx = left + width*0.5;
CGFloat cy = top + height*0.5;
CGFloat r = width*0.5;
CGMutablePathRef path = CGPathCreateMutable();
CGAffineTransform t = CGAffineTransformMakeTranslation(cx, cy);
t = CGAffineTransformConcat(CGAffineTransformMakeScale(1.0, height/width), t);
CGPathAddArc(path, &t, 0, 0, r, startAngle, endAngle, false);
CGContextAddPath(g->cg, path);
CGContextStrokePath(g);
CFRelease(path);