如果添加填充,CGContextDrawPath 描边消失
尝试绘制划分为动态提供的扇区数的圆。最后我的圆圈应该看起来像馅饼。
我创建了 Circle 类,其中包含许多馅饼。 Circle 有方法 - (void)draw
,它在 for (Pie *pie in self.pies)
循环中调用 [pie draw];
。
饼图的实现如下所示:
- (void)draw {
CGContextRef context = UIGraphicsGetCurrentContext();
float startAngleRads = degreesToRadians(_startAngle);
float endAngleRads = degreesToRadians(_endAngle);
CGContextBeginPath(context);
CGContextSetLineWidth(context, 1.0f);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGColorRef strokeColor = [_strokeColor CGColor];
CGContextSetStrokeColorWithColor(context, strokeColor);
CGColorRef fillColor = [_bgColor CGColor];
CGContextSetFillColorWithColor(context, fillColor);
CGContextMoveToPoint(context, _x, _y);
CGContextAddArc(context, _x, _y, _r, startAngleRads, endAngleRads, YES);
CGContextDrawPath(context, kCGPathStroke);
CGContextFlush(context);
}
这用扇区绘制了漂亮的圆圈,但当然没有任何填充。当我将最后几行更改为 CGContextDrawPath(context, kCGPathStrokeFill); 时,我的笔划线消失,只有最后一行(最后一个扇区)保留在屏幕上,圆圈的其他部分填充有背景颜色,并且没有笔划可见不再了。
问题是:我怎样才能绘制完全分离的“扇区”(每个扇区应该看起来像带有圆弧、描边和填充的三角形)。我需要这个,因为我想切换该扇区的可见性,但目前我什至不知道如何正确绘制它们。
如果这很重要,则所有绘制都发生在 self.opaque = NO;
的图层上。
trying to draw circle divided to dynamically provided number of sectors. In the end my circle should look like pie.
I've created class Circle which contains number of Pies inside. Circle has method - (void)draw
which calles [pie draw];
in for (Pie *pie in self.pies)
loop.
Implementation of pie looks like this:
- (void)draw {
CGContextRef context = UIGraphicsGetCurrentContext();
float startAngleRads = degreesToRadians(_startAngle);
float endAngleRads = degreesToRadians(_endAngle);
CGContextBeginPath(context);
CGContextSetLineWidth(context, 1.0f);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGColorRef strokeColor = [_strokeColor CGColor];
CGContextSetStrokeColorWithColor(context, strokeColor);
CGColorRef fillColor = [_bgColor CGColor];
CGContextSetFillColorWithColor(context, fillColor);
CGContextMoveToPoint(context, _x, _y);
CGContextAddArc(context, _x, _y, _r, startAngleRads, endAngleRads, YES);
CGContextDrawPath(context, kCGPathStroke);
CGContextFlush(context);
}
This draws nice circle with sectors but without any filling of course. When I change last lines to CGContextDrawPath(context, kCGPathStrokeFill);
my stroke lines disappears and only last line (last sector) stays at the screen, other parts of circle are filled with bgcolor and no stroke is visible anymore.
The question is: how can I draw completly separated "sectors" (every sector should look like triangle with Arc and Stroke and Fill). I need this because I want to toggle visibility of that sectors but at the moment I cant even figure out how to draw them correctly.
If this is important, all drawing happens on the layer with self.opaque = NO;
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,发现我的错误:必须在 CGContextAddArc 调用中设置
NO
。Ok, found my error: had to set
NO
inCGContextAddArc
call.