2
votes

I have a custom shape that i want to draw using UIBezierPaths and i want to use this drawing as a CALayer inside my view. The bezier path i use works if i draw it directly onto the UIView (inside drawRect). I want to know as to how i can use the same bezier drawing and perform the drawing inside my CALayer. I would then add this layer as a sub layer inside my view!

For instance lets say I'm drawing a concentric circle with my bezier paths and i want to draw this using a CALayer, how would i go about animating custom properties of the path, like its center, radius, startAngle and endAngle?

Specifically i want to know how i should

  1. Arrange my CALayer (initializing, drawing , upadte drawing ,etc)
  2. How do i draw the bezier inside my CALayer?
  3. How do i interact between the layer and the view that contains it?

Any help is appreciated!

1

1 Answers

4
votes

Here's how you create & draw a UIBezierPath in a CALayer. Using a CAShapeLayer is the easiest way:

UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:...]; 
CAShapeLayer *circleLayer = [CAShapeLayer layer];
circleLayer.path = circlePath.CGPath;
[self.view.layer addSublayer:circleLayer];

Here's a good tutorial on creating animatable properties in CALayers.