【问题标题】:Filling color in intersected path with UIBezierPath使用 UIBezierPath 在相交路径中填充颜色
【发布时间】:2013-09-25 03:32:44
【问题描述】:

我正在尝试绘制一个带有几个空心圆圈的视图。视图背景颜色将为黑色,不透明度为 0.5,并且在我可以看到其下方视图的地方出现空心圆圈。这在下面的代码中运行良好,但是当我的空心圆圈相交时出现问题,我想将它们都覆盖为空心区域,但由于奇怪的规则,这不起作用。有什么建议么? 或者有什么替代品?

- (void)addShadowView {
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height) cornerRadius:0];

    for (NSValue *point in self.hollowFrames) {
        UIBezierPath *circlePath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(point.CGPointValue.x - self.hollowCircleRadius.floatValue, point.CGPointValue.y - self.hollowCircleRadius.floatValue, 2.0 * self.hollowCircleRadius.floatValue, 2.0 * self.hollowCircleRadius.floatValue) cornerRadius:self.hollowCircleRadius.floatValue];

        [path appendPath:circlePath];
    }

    [path setUsesEvenOddFillRule:YES];

    CAShapeLayer *fillLayer = [CAShapeLayer layer];
    fillLayer.path = path.CGPath;
    fillLayer.fillRule = kCAFillRuleEvenOdd;
    fillLayer.fillColor = [UIColor blackColor].CGColor;
    fillLayer.opacity = 0.5;
    [self.layer addSublayer:fillLayer];
}

这就是现在的样子。我希望相交的区域也是空心的,而不是填充颜色。

【问题讨论】:

    标签: ios objective-c cocoa-touch uiview uibezierpath


    【解决方案1】:

    不要填满圆圈,剪掉中心。

    【讨论】:

    • 我不是在填充圆圈,而是用偶数/奇数规则填充 UIBezierPath。把圆圈剪掉是什么意思?
    • 创建一个与圆圈内部匹配的 cgpath 路径,将该路径添加到您的形状中,然后您可以在使用 eo 规则填充之前剪掉该部分。这会给你一个真正的“空心”圆圈,而不是一个中间有东西的圆圈。你的另一个选择是,如果你打算为你的圆圈使用纯色,你可以在一个矩形内画一个椭圆,这会给你同样的效果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-23
    • 1970-01-01
    • 2023-04-10
    • 2015-06-02
    • 1970-01-01
    • 1970-01-01
    • 2021-07-05
    相关资源
    最近更新 更多