On iOS, why does setting a layer's sublayerTransform turn itself to act like CATranformLayer?

◇◆丶佛笑我妖孽 提交于 2019-12-03 00:31:23

To really understand the difference between a layer transform and sublayerTransform properties, I think it is useful to think of this in terms of looking at a TV with 3D content in it. Check out my modified version of your code in Swift playground.

Here's the beginning version: you have a TV with content consisting of no perspective transformation whatsoever. Therefore, your content (the two orange and yellow sublayers) looks flat even with rotation around the y-axis. Pretty much what you'd expect for an orthographic projection.

However, if you hold your TV still, but transform your content underneath with perspective projection, now you immediately see the depth of your content. The zPosition of the sublayers you added truly play an important part in giving you a sense of depth, and it is rightfully so by its definition. This is exactly how sublayerTransform works: transform only the contents, but not the TV itself.

Now, what would it look like if I use transform instead of sublayerTranform? Imagine not transforming just the contents, but rotate the entire TV along with the contents attached to the screen, and you'd see the expected result:

So, yeah, apparently transform and sublayerTransform behave quite differently when it comes to treating zPosition of the sublayers, although the documentation doesn't explicitly say so. A sublayer's zPosition has no effect on its parent's transform, but does provide normal 3D effect on its parent's sublayerTransform.

we can think the layer as a coordinate layer , when we make a layer transfrom3D, it coordinate become 3D,but its subLayer still show as 2D,but when set sublayer transfrom3D,the layer will make its all sublayer show as 3D.it is the same as the rotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!