我正在用一些CGRects和Ellipses来制作一个复杂的形状。一旦创建完成,我想要打开这条路。当我抚摸它的路径时,它会抚摸每个形状。有没有办法可以将每个形状合并为一个单独的路径,所以笔画不会相交?将多个CGPath合并为一个路径
int thirds = self.height/3;
CGPathRef aPath = CGPathCreateMutable();
CGRect rectangle = CGRectMake((58 - 10)/2, 46, 10, self.height - 58);
CGPathAddRect(aPath, nil, rectangle);
CGPathAddEllipseInRect(aPath, nil, CGRectMake((58 - 48)/2, 0, 48, 48));
CGPathAddEllipseInRect(aPath, nil, CGRectMake((58 - 48)/2, thirds, 48, 48));
CGPathAddEllipseInRect(aPath, nil, CGRectMake((58 - 48)/2, thirds * 2, 48, 48));
CGPathAddEllipseInRect(aPath, nil, CGRectMake(0, self.height - 58, 58, 58));
CGPathCloseSubpath(aPath);
CGPathRef other = CGPathCreateCopy(aPath);
CAShapeLayer *square = [CAShapeLayer layer];
square.fillColor = [UIColor colorWithRed:36/255.0f green:56/255.0f blue:82/255.0f alpha:1.0f].CGColor;
square.strokeColor = [UIColor colorWithRed:50/255.0f green:70/255.0f blue:96/255.0f alpha:1.0f].CGColor;
square.path = other;
[self.layer addSublayer:square];
UPDATE
我试着用添加路径一起,我得到了完全相同的结果
CGPathAddPath(aPath, nil, CGPathCreateWithRect(rectangle, nil));
CGPathAddPath(aPath, nil, CGPathCreateWithEllipseInRect(CGRectMake((58 - 48)/2, 0, 48, 48), nil));
CGPathAddPath(aPath, nil, CGPathCreateWithEllipseInRect(CGRectMake((58 - 48)/2, thirds, 48, 48), nil));
CGPathAddPath(aPath, nil, CGPathCreateWithEllipseInRect(CGRectMake((58 - 48)/2, thirds * 2, 48, 48), nil));
CGPathAddPath(aPath, nil, CGPathCreateWithEllipseInRect(CGRectMake(0, self.height - 58, 58, 58), nil));
'CGPathAddPath(PATH1,NULL,PATH2)' – CodaFi
@CodaFi因此,为每个形状创建一个新路径并使用'CGPathAddPath'? – brenjt