I want to implement a view having two layers on it. Then i want to do some drawing on these layers separately on press of some buttons.
I have implemented delegate method:
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context
but problem is that this delegate is only fired with [myviewclass setNeedsDisplay] method(not by [mylayer setNeedsDisplay])and then drawLayer gets called for view’s root layer always.
I want it to get called for mylayer with accurate context so that i can do drawing on the specific layer using its context.
Please help how to achieve this.
You must set the delegate of the layer and implement the delegate method
drawLayer:inContext:in it. Otherwise, the layer can’t determine in which object it has to call that method.Also, the delegate of the layer can’t be the
UIView, so you must use something else as a delegate.You can use the view controller for example as the delegate of your layers. First, implement the method
drawLayer:inContext:in the view controller. Then, set the view controller as the delegate of your layers.