开发者

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 overriding drawRect.
  • 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:

  1. Subclass CALayer and implement -drawInContext:.
  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜