Skip to content

CATransform3D.fromAffineTransform() static method ​

The CATransform3D.fromAffineTransform() static method turns a two-dimensional CGAffineTransform into a three-dimensional transform with the same effect.

Syntax ​

CATransform3D.fromAffineTransform(transform)

Parameters ​

transform

A CGAffineTransform, or a plain object with the six fields a, b, c, d, tx, and ty.

Return value ​

A new CATransform3D. The six numbers go to the corresponding positions, and the z direction is unchanged:

CGAffineTransform fieldGoes to
am11
bm12
cm21
dm22
txm41
tym42

m33 and m44 are 1, and the rest are 0. To go the other way and take the two-dimensional part, use affineTransform.

Exceptions ​

TypeError

  • transform is not an object: fromAffineTransform needs an object with all of: a, b, c, d, tx, ty.
  • transform is missing a field, or a field cannot be converted to a finite number: fromAffineTransform is missing tx, or it is not a finite number, with the missing field name in the middle.

Examples ​

js
const flat = new CGAffineTransform(1, 2, 3, 4, 5, 6);
const t = CATransform3D.fromAffineTransform(flat);
console.log(t.m11, t.m12, t.m21, t.m22, t.m41, t.m42, t.m33, t.m44);

Result: logs 1 2 3 4 5 6 1 1.

Corresponding iOS API ​

CATransform3DMakeAffineTransform(m).

See also ​