Drawing with Core Graphics in a CALayer
I'm trying to get my开发者_如何学C head around Core Graphics and Core Animation. I understand the following:
- Using
UIView
, I can draw with Core Graphics by overridingdrawRect
. - I can create multiple
CALayer
's and set their properties and have them added
My questions are:
- If I create a CALayer
from scratch (not using something like CALayer *myLayer = myUIView.layer
), what is the approach to draw in that CALayer
?
- What's the CALayer's equivalent of drawRect
for UIView?
I hope that makes sense.
To do custom drawing you have two options:
- Subclass
CALayer
and implement-drawInContext:
. - Make your own class that serves as your layer's delegate to perform the Quartz routines. It should implement
-drawLayer:inContext:
.
You should add your custom layer as a sublayer to your UIView
's layer. You should take a spin through CALayer
's doc pages for some rules about how to interact with the view's layer.
精彩评论