Michael
Michael

Reputation: 33307

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?

Upvotes: 3

Views: 786

Answers (1)

Martin R
Martin R

Reputation: 539935

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)

Upvotes: 6

Related Questions