Search code examples
iosobjective-cswiftcatransform3d

How to combine 2 3D Rotations without canceling each other?


I have a view which I want to rotate in two different directions.

The first is:

arrowImageView.layer.transform = CATransform3DMakeRotation(rotationAngle, 0, 0, 1)

and the second is:

arrowImageView.layer.transform = CATransform3DMakeRotation(pitch, 1, 0, 0)

How can I combine these two rotations without canceling one out?


Solution

  • You combine 3D transformations with CATransform3DConcat():

    let t1 = CATransform3DMakeRotation(rotationAngle, 0, 0, 1)
    let t2 = CATransform3DMakeRotation(pitch, 1, 0, 0)
    arrowImageView.layer.transform = CATransform3DConcat(t1, t2)