Search code examples
ioscore-animationcalayer

What's the difference between setting the zPosition of a layer vs changing it via CATransform3DTranslate


I have a layer where I am modofying its m34 transform property to get perspective. I would have expected that by changing the zPosition, the size will change (as it appears further away) however when I set the zPosition property, the size does not change, but it does when I use CATransform3DTranslate.

Why is this? What's the difference between the following:

CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0 / -4000;
myLayer.transform = transform;
myLayer.zPosition = -500;

and

CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0 / -4000;
transform = CATransform3DTranslate(transform, 0, 0, -500);
myLayer.transform = transform;

The latter works how I expect, but I want to understand why the first does not.


Solution

  • zPosition is just for the drawing order of siblings layers, not for perspective drawing: you can use it to get a "bring to front" / "send to back" effect without adding/removing the layer.