I have a class which is a subclass of UIView
. I am able to draw stuff inside the view either by implementing the drawRect
method, or by implementing drawLayer:inContext:
which is a delegate method of CALayer
.
I have two questions:
- How to decide which approach to use? Is there a use case for each one?
If I implement
drawLayer:inContext:
, it is called (anddrawRect
isn't, at least as far as putting a breakpoint can tell), even if I don't assign my view as theCALayer
delegate by using:[[self layer] setDelegate:self];
how come the delegate method is called if my instance is not defined to be the layer's delegate? and what mechanism prevents
drawRect
from being called ifdrawLayer:inContext:
is called?