从CGPath修剪/减去CGPath? [英] Trim/subtract CGPath from CGPath?

查看:162
本文介绍了从CGPath修剪/减去CGPath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have some CGPath (a poly with two circle) carried out on a CAShapeLayer.

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

推荐答案

而不是做数学,结果可以在绘图时使用 kCGBlendModeClear 实现。

Instead of do the math, the result can be achieved at drawing time using kCGBlendModeClear.

// 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);

这篇关于从CGPath修剪/减去CGPath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆