What's the difference between CALayer -drawInContext: and -renderInContext: ?
Working with UIViews happens on the main thread, it means it is using CPU power. CALayer: Layers on other hand have simpler hierarchy. That means they are faster to resolve and quicker to draw on the screen. There is no responder chain overhead unlike with views.
An object that manages image-based content and allows you to perform animations on that content.
All UIView subclasses have a layer property, which is responsible for drawing their contents efficiently. These layers are powered by Core Animation, which handles all the drawing and animation that UIKit requests.
the main different between a view and a layer is that views can accept user input while a layer cannot. a layer is simply a graphical representation. views can handle user taps, drags, pinches, etc. to me, this is all you need to know.
When providing custom Quartz-drawn content to display within a CALayer, you can override -drawInContext:
and do your custom drawing there. This is similar to -drawRect:
for a UIView or NSView. Alternatively, you can set another class to be the delegate of the CALayer and implement -drawLayer:inContext:
to provide custom content to a standard CALayer.
You don't override -renderInContext:
, but instead you can call this on a layer to render it and all of its sublayers into a particular Core Graphics context. Note that this won't render certain types of layers (like those with OpenGL content). It also doesn't behave the way you'd expect when rendering into a PDF context, where the layers will come out as bitmapped rectangles instead of pure vector elements. To work around this, you might want to check out the Core Plot framework's CPTLayer implementation, where we bypass the normal rendering process in order to preserve the vectors in a PDF generated from our CALayer subclass.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With