ios - 核心图形只填充了我图的一部分

标签 ios objective-c uiview core-graphics

当我尝试填充图形时,它只会填充弧线。看一张图就明白了: enter image description here

我也想填充圆弧下的矩形,但我不明白为什么不填充。

这是我的代码:

    CGContextSetStrokeColorWithColor(context, wormBorderColor);
    CGContextSetFillColorWithColor(context, wormFillColor);

    //Tracer la ligne de gauche
    CGContextMoveToPoint(context, leftX, startingY);
    CGContextAddLineToPoint(context, leftX, startingY-wormHeight);

    CGContextMoveToPoint(context, rightX, startingY-wormHeight);
    CGContextAddArc(context, centerX, startingY-wormHeight, echelleSize/2, 0,M_PI , 1);


    CGContextMoveToPoint(context, rightX, startingY-wormHeight);
    CGContextAddLineToPoint(context, rightX, startingY);


    //CGContextStrokePath(context);
    CGContextDrawPath(context, kCGPathFillStroke);

谢谢。请原谅我糟糕的英语和我糟糕的核心图形知识。

最佳答案

要使填充正常工作,您需要有一个闭合路径。每次执行 CGContextMoveToPoint 时,都会中断路径。尝试删除圆弧和矩形第二边的 CGContextMoveToPoint。如果圆弧和矩形不匹配,您可能需要在 CGContextAddArc 中翻转开始和结束角度,因为它可能在错误的点开始和结束。

关于ios - 核心图形只填充了我图的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21162807/

相关文章:

ios - CGAffine 使用 UIPanGestureRecognizer 转换 UIView

ios - UITableview在每行出现之前无法平滑滚动?

objective-c - 转换从 View :toView:duration:options:completion: is not animating the transition

ios - 无法分配给属性 'observationTime' 是一个只读属性

ios - 如何使用 AFNetworking 在 iPhone 模拟器中通过 VPN IP 地址进行连接?

ios - 拦截 UIWebView 中 WebSocket 连接的响应

ios - 在 UIView 中动态添加和居中 UIImages

Iphone UIView 切换 : Previous view's subviews polluting newly switched-to view

ios - 检查设备日期设置是否在 iOS 中是自动的

ios - 在 Swift 中嵌套 UIScrollView