首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >修剪/减去CGPath从CGPath?

修剪/减去CGPath从CGPath?
EN

Stack Overflow用户
提问于 2013-10-14 13:24:54
回答 2查看 2K关注 0票数 10

我有一些CGPath (一个带有两个圆圈的多边形)在CAShapeLayer上执行。

我可以像这样修剪/减去路径吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-10-14 17:55:09

kCGBlendModeClear代替数学运算,可以在绘图时间内得到结果。

代码语言:javascript
复制
// Create the poly.
CGContextBeginPath(context);
CGContextMoveToPoint       (context, a_.x, a_.y);
CGContextAddLineToPoint    (context, b_.x, b_.y);
CGContextAddLineToPoint    (context, c_.x, c_.y);
CGContextAddLineToPoint    (context, d_.x, d_.y);
CGContextClosePath(context);

// Draw with the desired color.
CGContextSetFillColorWithColor(context, self.color.CGColor);
CGContextFillPath(context);

// Create a circle.
CGContextBeginPath(context);
CGContextAddEllipseInRect(context, (CGRect){
    b_.x - self.radius,
    b_.y - self.radius,
    self.radius * 2.0,
    self.radius * 2.0 });
CGContextClosePath(context);

// Draw with Clear (!) blend mode.
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextSetFillColorWithColor(context, self.color.CGColor);
CGContextFillPath(context);
票数 6
EN

Stack Overflow用户

发布于 2021-07-10 18:48:48

基于Geri's answer,使用Swift 5

代码语言:javascript
复制
context.addPath(path1) // your original CGPath
context.setFillColor(color1) // your color
context.fillPath()
        
context.addPath(path2) // your clearing CGPath
context.setBlendMode(.clear) // draw with clear mode
context.fillPath()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19361294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档