Order iPhone CALayer Stack

I am using CALayers for drawing in a UITableViewCell. I am trying to figure out how the layers with the contents of a UITableViewCell are ordered. For instance:

  • I add labels in a UITableViewCell to my cellForRow method: atIndexPath
  • In the drawRect method for UITableViewCell, I draw some content using the current context
  • Also, in drawRect I add some sublayers

So what will be the order of these elements. I know that I have ZPosition on CALayers, but I'm not sure that they are always on top of any UITableViewCell routines. And I'm not sure where the content that is drawn in drawRect comes in order. Any help or documentation links would be great. I read the Core Animation Programming Guide and have not seen anywhere where this will be answered.

+3
source share
2 answers
  • Your UITableViewCell (or derived class) comes from a UIView. It has one CALayer, access to which you can get through the layer property. This layer occupies the entire field of view. The UILabels that you add to the cell view will be children of your UIView of your cell, and their CALayer will be a child of CALayer. Children's layers are drawn in front of parents.
  • When you draw anything in the UIView drawRect method, the CALayer owned by the UIView will be supported by the bitmap. Your UILabels will hide this bitmap partially or completely depending on how large they are.
  • CALayers, , UILabel, , , ( , , ).

, UITableViewCell . 4 /.

+3

CALayers , . . zPosition . , sublayers ( , , , ).

, , UITableViewCell ( UIView ).

, UITableViewCell -drawRect:. UITableViewCell. CALayers . - , UITableViewCell , , .

+4

Source: https://habr.com/ru/post/1739314/


All Articles