What's the proper order to rotate and translate an CALayer with CATransform3D
<p>I have a CALayer which I want to translate and rotate at the same time. I have the following codes which can work actually:</p>
<pre><code>    // layer 1:
    // translate: (△x, △y, △z) = (length/2, 0, length/2)
    // rotate around y: 90 degree
    CATransform3D transformLayer1 = CATransform3DIdentity;
    transformLayer1 = CATransform3DTranslate(transformLayer1, length/2, 0, length/2   );
    transformLayer1 = CATransform3DRotate(transformLayer1, M_PI_2, 0, 1, 0);
    self.layer1.transform = transformLayer1;
</code></pre>
<p>During my test, I find <strong>the transforming result will be different if I change the order of translation and rotation</strong>, for example, the codes are changed like this:</p>
<pre><code>    CATransform3D transformLayer1 = CATransform3DIdentity;

    // do rotation firstly, and then translation
    transformLayer1 = CATransform3DRotate(transformLayer1, M_PI_2, 0, 1, 0);
    transformLayer1 = CATransform3DTranslate(transformLayer1, length/2, 0, length/2   );
    
    self.layer1.transform = transformLayer1;
</code></pre>
<p><a href="https://i.stack.imgur.com/SK1Hr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SK1Hr.png" alt="enter image description here" /></a></p>
<p>In the debugging, I print the value of the transform matrix at each step. The results show the value of m43 are different. Is there anyone who can explain why this happened? Or how to understand the Core Animation functions of CATransform3DTranslate() and CATransform3DRotate() ?</p>