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 - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How can I add media attachments to my push notific
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 assubLayers
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.
A CATransformLayer is used to transform its sublayers in 3D, and does NOT flatten them down.
It’s something you’d use if you want to do a transform on a group of layers together but you didn’t want to do to each one individually because you wanted the flexibility of changing the transform in one place...kind of like a camera / world / model transform in OpenGL.
That said, I’ve never had occasion to use one, because I’ve never tried to do true 3D in LayerKit. I assume one was used for that stacking demo at WWDC a few years ago, there might be example code for that.
If I found myself starting to use a CATransformLayer nowadays, I’d switch to SceneKit, but that’s not on iOS yet.