1

I'm working on a project where I'm using a CAShapeLayer to render a grid behind some content. The problem is that the OS creates multiple instances of this CAShapeLayer subclass, when I'm expecting one.

First, I subclassed CAShapeLayer, overriding init and layoutSublayers (the layer has a few sublayers that render additional content).

Then, I overrode +[UIView layerClass] in the view that uses my CAShapeLayer subclass.

Lastly, the view using my layer was added as a subview to a UIScrollView.

To reference self.layer (in the view) with the correct class (GridLayer vs CALayer), I created the following property:

@property (nonatomic, weak, readonly, getter=graphLayer) GraphLayer *graphLayer;

and getter

- (GraphLayer *)graphLayer {
    return (GraphLayer *)self.layer;
}
Nate Symer
  • 2,185
  • 1
  • 20
  • 27

0 Answers0