如何使用 QuartzCore 绘制一个有孔的形状?
这是一个例子:
我已经了解如何绘制路径:
CGMutablePathRef maskPath = CGPathCreateMutable();
CGPathMoveToPoint(maskPath, NULL, x1, y1);
CGPathAddLineToPoint(maskPath, NULL, x2, y2);
CGPathAddLineToPoint(maskPath, NULL, x3, y3);
CGPathCloseSubpath(maskPath);
并将其应用到 UIView:
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = viewToMask.bounds;
maskLayer.path = maskPath;
viewToMask.layer.mask = maskLayer;
但我不完全确定如何创建一条中心有孔的路径。 我是否需要以某种方式从路径中减去?
最佳答案
由于您将 CGPath 设置为要作为 mask 的 CAShapeLayer 的路径属性,因此您应该查看 Crop a CAShapeLayer retrieving the external path和 its answer 。
关于objective-c - quartz 核 : Draw a shape with a hole in it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10922190/