I have a CAShapeLayer that takes his shape fr开发者_高级运维om path. This creates a layer object which can be manipulated, like move and rotate. My problem is that I need the layer object to be composed of multiple paths. For example imagine the United States map; there is the main shape and also the Alaska. Both shapes are not connected, but they are the same entity and I need them to be a single object in a single CAShapeLayer, so that when I move the layer both US and Alaska move together.
UIBezierPath* ahPath = [self mydPath];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = ahPath.CGPath;
...
[self.layer addSublayer:shapeLayer];
In the case you describe I would make a CAShapeLayer representing the US and a separate CAShapeLayer representing a state, then add the state layer to the US layer. Moving the US layer would automatically move the state layer with it. The advantage is that you can color the US and states differently.
Also be aware that a CGPath
can contain multiple subpaths, so one CGPath
can contain the US and Alaska. Check the Overview in CGPath Reference.
精彩评论