Ios – Multiple paths in CAShapeLayer

cocoacocoa-touchcore-animationcore-graphicsios

I was wondering if it is somehow possible to let a CAShapeLayer stroke more than only one path since actually it only takes one path as parameter like:

CAShapeLayer* myLayer=[CAShapeLayer layer];
myLayer.path=myBezierPath

But what if I would like to stroke more than one path onto that layer?

Best Answer

Use

void CGPathAddPath (
  CGMutablePathRef path1,     // The mutable path to change.
  const CGAffineTransform *m, // A pointer to an affine transformation matrix, or NULL if no transformation is needed. If specified, Quartz applies the transformation to path2 before it is added to path1.
  CGPathRef path2             // The path to add.
);

Code example:

CGMutablePathRef combinedPath = CGPathCreateMutableCopy(path.CGPath);
CGPathAddPath(combinedPath, NULL, path2.CGPath);
CGPathAddPath(combinedPath, NULL, path3.CGPath);
CGPathAddPath(combinedPath, NULL, path4.CGPath);
myLayer.path = combinedPath;