我需要绘制复杂的形状,如下所示:
所以我试试:
CGFloat offsetAngle = 15 * M_PI/180;
CGPathAddArc(path, nil, 39/2, 30, 39/2-0.1, offsetAngle, -M_PI-offsetAngle, YES);
CGFloat linesXOffset = 2.5;
CGFloat linesYOffset = 30;
CGPathMoveToPoint(path, nil, linesXOffset, linesYOffset);
CGPathAddLineToPoint(path, nil, 39-linesXOffset, linesYOffset);
CGPathAddLineToPoint(path, nil,39/2,//X
linesYOffset + CGRectGetHeight(self.bounds)/2-220/2-linesYOffset);
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayer setPath:path];
因此形状由三角形和弧形组成。
但我有以下重叠问题:
可以修复吗?
答案 0 :(得分:3)
1)更容易:
CGFloat linesYOffset = 35;
2)另一种方式:
CGFloat offsetAngle = 15 * M_PI/180;
CGMutablePathRef path1 = CGPathCreateMutable();
CGPathAddArc(path1, nil, 39/2, 30, 39/2-0.1, offsetAngle, -M_PI-offsetAngle, YES);
CGMutablePathRef path2 = CGPathCreateMutable();
CGFloat linesXOffset = 5.5;
CGFloat linesYOffset = 30;
CGPathMoveToPoint(path2, nil, linesXOffset, linesYOffset);
CGPathAddLineToPoint(path2, nil, 39-linesXOffset, linesYOffset);
CGPathAddLineToPoint(path2, nil,39/2,//X
linesYOffset + 600/2-220/2-linesYOffset);
CAShapeLayer *shapeLayer1 = [CAShapeLayer layer];
[shapeLayer1 setPath:path1];
CAShapeLayer *shapeLayer2 = [CAShapeLayer layer];
[shapeLayer2 setPath:path2];
CAShapeLayer* container = [CAShapeLayer layer];
[container addSublayer:shapeLayer1];
[container addSublayer:shapeLayer2];