1

我需要绘制复杂的形状,如下所示: 在此处输入图像描述

所以我尝试:

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];

所以形状由三角形和弧形组成。

但我有以下叠加问题:

在此处输入图像描述

有可能修复吗?

4

1 回答 1

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];
于 2013-07-09T14:09:57.570 回答