gpt4 book ai didi

ios - CGPath裁剪

转载 作者:行者123 更新时间:2023-11-28 21:29:38 25 4
gpt4 key购买 nike

我想做类似这样的东西:

Example

我尝试了以下代码:

CGMutablePathRef path = CGPathCreateMutable();
CGPathAddLines(path, &CGAffineTransformIdentity, points, sizeof points / sizeof *points);

CGMutablePathRef strokePath = (CGMutablePathRef)CGPathCreateCopyByStrokingPath(path, &CGAffineTransformIdentity, data.lineWidth, kCGLineCapRound, kCGLineJoinMiter, 4.f);

for(NSInteger i = 0; i < [data.values count]; i++) {
CGRect rect = CGRectMake(points[i].x - data.dotRadius, points[i].y - data.dotRadius, data.dotRadius * 2, data.dotRadius * 2);
CGPathAddEllipseInRect(strokePath, &CGAffineTransformIdentity, rect);
CGPathAddEllipseInRect(strokePath, &CGAffineTransformIdentity, CGRectInset(rect, data.lineWidth, data.lineWidth));
}

然后绘制这条路径:

CAShapeLayer *layer = self.layers[line];
layer.path = strokePath;
layer.strokeColor = nil;
layer.fillColor = data.lineColor.CGColor;
layer.fillRule = kCAFillRuleEvenOdd;

Bt 给出类似的东西:

Result

有谁知道我如何才能做到这一点?

最佳答案

画线和圆,不是复合路径,而是两条线和一个圆(没有任何填充规则)。然后使用 kCGBlendModeClear 绘制一个较小的实心圆,“打出”圆心的孔。

或者,首先剪掉圆心的孔。然后画线和圆。

关于ios - CGPath裁剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36688524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com