CATransform3D vs. CGAffineTransform?

12,178

Solution 1

As MSN said, they are used in different cases. CGAffineTransform is used for 2-D manipulation of NSViews, UIViews, and other 2-D Core Graphics elements.

CATransform3D is a Core Animation structure that can do more complex 3-D manipulations of CALayers. CATransform3D has the same internal structure as an OpenGL model view matrix, which makes sense when you realize that Core Animation is built on OpenGL (CALayers are wrappers for OpenGL textures, etc.). I've found that this similarity of internal structure, combined with some nice helper functions that Apple provides, can let you do some neat OpenGL optimizations, as I post here.

When it comes down to choosing which do use, ask yourself if you're going to work with views directly in a 2-D space (CGAffineTransform) or with the underlying Core Animation layers in 3-D (CATransform3D). I use CATransform3D more frequently, but that's because I spend a lot of time with Core Animation.

Solution 2

One is for linear 2d transformations, the other is for three dimensional projected transformations. At least that's what I could glean from the documentation.

If you don't need to render 3d projected onto the screen, use the affine transform. Otherwise, use the 3d transform. The 3d transform is essentially a 4x4 matrix, while the 2d affine one is 3x2.

Share:
12,178

Related videos on Youtube

Corey Floyd
Author by

Corey Floyd

An iPhone developer, now in Philly!

Updated on April 16, 2022

Comments

  • Corey Floyd
    Corey Floyd about 2 years

    Whats the difference between the two?

    I'm sure they have pros and cons, and situations they are better performers in.

    Any resources that compare the two?

    Is one better for animation (I imagine the CATransform3D)? Why?

    Also I think I read somewhere that text clarity can be an issue, is one better at scaling text?

  • plinth
    plinth about 15 years
    2D Affine is usually 3 wide x 2 high (with an invisible implied identity in the bottom row).
  • Will Larche
    Will Larche over 8 years
    I was having a problem with flickering / reduced framerate and this fixed it!