I saw this solution while researching for CALayers. I was looking for a way to implement custom drawings inside a UIView with multiple sublayers. I named my sublayers like this:
layer1.name = @"Back";
layer2.name = @"Middle";
layer3.name = @"Front";
And I created custom methods to be implemented by this layers
-(void)drawBackLayer:(CALayer *)layer inContext:(CGContextRef)ctx
-(void)drawMiddleLayer:(CALayer *)layer inContext:(CGContextRef)ctx
-(void)drawFrontLayer:(CALayer *)layer inContext:(CGContextRef)ctx
The problem is these methods are not implemented, instead the drawLayer:inContext:
, which is being used by the view's root layer, is implemented four times. This means that the custom layers implement this method instead of the custom methods. Can anyone explain to me why?
NOTE: the solution I am referring in the link is the code provided by Dave Lee.