What are layers for? What should I do with adding a layer, and why should I think about layers?

I am wondering what makes layers different from Views when each view comes with its own layer. Maybe I'm wrong. But then: what are these layers for?

As I understand it, I would use UIView to group elements in my GUI. I could also use this UIView to position things over other things. So where are the layers here?

Should I think of them in the same way as z-index, as in HTML / CSS? Are they interesting for Core Animation?

+3
source share
2 answers

Compared to UIVIews, CALayers

  • easy
  • with time information for animation
  • Some things are harder to draw, like text (like unicode).

If you have less than 20 or so, it probably doesn't matter. If you have complex animation needs or just a ton of drawing layers, you can use CALayers instead.

+2
source

On the iPhone, I have no significant performance difference between using UIViews and CALayers. The Mac is a completely different story in which NSViews are significantly heavier.

Working with CALayers (or at least support for the presentation level) is sometimes necessary for complex animations, in particular keyframe animations or movement along a path.

In addition, CALayers can be used to create platform-independent user interfaces (Mac and iPhone). UIViews are very different from NSViews, but CALayers are identical between the iPhone and Mac OS X Leopard (in addition to several features not found on the iPhone). I used CALayers to share interface code between an iPhone application and its Mac counterpart.

+1
source

All Articles