When should we use CATransformLayer?

core-animation, ios, objective-c

Solution

To fully understand what are the differences between CALayer and CATransformLayer, you should read this article

It is the best tutorial which explains how to use `CATransformLayer`.

But to say briefly, Consider a scene(`CAlayer instance`) where we create 4 planes at the same X, Y coordinates but with different Z and add it as `subLayers` to scene.And rotate the scene by some angle.

So, we might expect it looks like,

But instead it looks like,

This is due to the fact that a CALayer is incapable of managing the depth of a 3D hierarchy and it just flattens the scene to a single Z level. To correct that depth issue, we use `CATransformLayer`, it has depth understanding and renders based on it.

Note:images are taken from the article.

Problem

I have read the documentation and several examples, but still cannot understand when exactly to use a `CATransformLayer`. A normal `CALayer` flattens everything at the `z = 0` plane, but isn't that what a `CATransformLayer` does too? A mathematical explanation would be very helpful.

Original source