iOS – Set the zPosition of the layer and change between the change of the layer via Catransform3DTranslate

I have a layer and I am modifying its m34 transform property to obtain a perspective view.
I originally expected that by changing the zPosition, the size would change (because it looks farther away ) But when I set the zPosition property, the size will not change, but when I use CATransform3DTranslate it will change.

Why? The following are the differences:

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

and

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

The role of the latter is in line with my expectations, but I want to understand why The first one does not.

zPosition is only applicable to the drawing order of sibling layers, not to Perspective: You can use it to get the “bring to the front”/”send to the back” effect without adding/removing layers.

I have a layer, which I am modifying Its m34 transform property to get the perspective view.
I originally expected that by changing the zPosition, the size would change (because it looks further away) but when I set the zPosition property, the size does not change, but when I use CATransform3DTranslate It will change.

Why is this? The following are the differences:

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

and

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

The role of the latter is in line with my expectations, but I want to understand why The first one does not.

zPosition only applies to the drawing order of the sibling layers, not to the perspective view: you can use it to get the Front”/”Send to Back” effect without adding/removing layers.

Leave a Comment

Your email address will not be published.