【问题标题】:QuartzCore: Draw a shape with a hole in it?QuartzCore:画一个有洞的形状?
【发布时间】:2012-06-06 20:58:30
【问题描述】:

如何使用 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;

但我不完全确定如何创建一条中心有一个洞的路径。 我是否需要以某种方式从路径中减去?

【问题讨论】:

标签: objective-c cgpath quartz-core


【解决方案1】:

由于您将 CGPath 设置为 CAShapeLayer 的路径属性以作为掩码,因此您应该查看 Crop a CAShapeLayer retrieving the external pathits answer

【讨论】:

    猜你喜欢
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2013-12-22
    • 1970-01-01
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多