alex
alex

Reputation: 279

Constructing CAShapeLayer from a multiple CGpaths

I have a CAShapeLayer that takes his shape from 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];

Upvotes: 2

Views: 2743

Answers (2)

marsl
marsl

Reputation: 1029

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

Upvotes: 0

Costique
Costique

Reputation: 23722

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.

Upvotes: 2

Related Questions