objective-c - quartz 核 : Draw a shape with a hole in it?

标签 objective-c cgpath quartz-core

如何使用 QuartzCore 绘制一个有孔的形状?

这是一个例子: enter image description here

我已经了解如何绘制路径:

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/

相关文章:

iphone - 具有玻璃效果的 UIView

objective-c - 为什么需要 '@objc' 来检查 Swift 中的协议(protocol)一致性?

ios - 取消选择 RowAtIndexPath 问题

cocoa - CGPathApplierFunction 的异常

ios - 在可缩放的 UIView 中保留 CAShapeLayer 的 lineWidth

objective-c - renderInContext 在视网膜和非视网膜设备上

ios - 从 CMSampleBuffer 制作 UIImage

objective-c - NSPathControl 和自动布局

ios - 向核心数据对象或属性添加弃用

sprite-kit - 如何创建波浪路径 Swift