我们什么时候应该使用CATransformLayer? [英] When should we use CATransformLayer?

查看:71
本文介绍了我们什么时候应该使用CATransformLayer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了文档和一些示例,但是仍然无法理解何时确切使用 CATransformLayer 。正常的 CALayer 使 z = 0 平面上的所有内容变平,但这不是 CATransformLayer 也可以吗?数学上的解释将非常有帮助。

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.

推荐答案

要完全了解CALayer和CATransformLayer之间的区别,您应该阅读文章

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

这是最好的教程,解释了如何使用 CATransformLayer

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

不过要简单地说,

考虑一个场景( CAlayer实例),在该场景中我们在相同的X,Y坐标但具有不同的Z轴上创建4个平面,并将其添加为 subLayers 到场景。然后将场景旋转一定角度。

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.

因此,我们可能希望它看起来像

< img src = https://i.stack.imgur.com/gT6CW.png alt =在此处输入图片描述>

So, we might expect it looks like,

但是看起来,

But instead it looks like,

这是由于CALayer无法管理3D镜头的深度稀疏且仅将场景展平到单个Z层。要更正该深度问题,我们使用 CATransformLayer ,它具有深度了解并基于此进行渲染。

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.

注意:图片摘自本文。

这篇关于我们什么时候应该使用CATransformLayer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆