2

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];
alex
  • 279
  • 4
  • 14
  • Hi alex. I am facing the same problem. I have CAShapeLayers which are contained in another CAShapeLayer. Can you throw idea on how you implemented move functionality on this. – Harsh Feb 23 '12 at 06:08

2 Answers2

2

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.

Costique
  • 23,712
  • 4
  • 76
  • 79
  • @alex Glad to hear. Please mark the answer as accepted as that will help you receive more quality answers in the future. And welcome to SO! – Costique Feb 12 '11 at 10:45
0

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

martinjbaker
  • 1,424
  • 15
  • 23
marsl
  • 959
  • 1
  • 14
  • 25