Tôi đang tạo một hình dạng phức tạp bằng cách sử dụng một vài CGRects và Ellipses. Tôi muốn đột quỵ con đường đó một khi nó đã được tạo ra. Khi tôi đột quỵ con đường nó đột quỵ từng hình dạng. Có cách nào tôi có thể hợp nhất từng hình dạng thành một đường dẫn duy nhất, do đó đột quỵ không giao nhau?Kết hợp nhiều CGPath với nhau để tạo một đường dẫn
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];
CẬP NHẬT
tôi đã cố gắng với việc thêm đường dẫn với nhau và tôi đã cùng kết quả chính xác
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 Vì vậy, tạo ra một con đường mới cho mỗi hình dạng và sử dụng 'CGPathAddPath'? – brenjt