Suragch
Suragch

Reputation: 512406

CTM transforms vs Affine Transforms in iOS (for translate, rotate, scale)

I read through the Transforms documentation in the Quartz 2D Programming Guide. In it there appears to be two ways to make transformations. One way is through modifying the Current Transformation Matrix (CTM). It has methods like the following:

The other way is to use Affine transforms. It has methods like the following:

The docs state

The affine transform functions available in Quartz operate on matrices, not on the CTM.

But I don't understand how that affects me practically. It seems like I can get the same result using either method. When should I use the CTM transforms and when should I use the Affine transforms?

Upvotes: 1

Views: 1187

Answers (1)

Matic Oblak
Matic Oblak

Reputation: 16774

CTM is a current transformation matrix and the CTM methods will make operations on the current matrix.

The other version of functions will make the transformation on a given matrix which means you need to specify which matrix you are trying to transform. After you did so you may apply the transform to the CTM any way you want or use it for any other purpose.

For instance these 2 operations would be the same:

CGContextTranslateCTM(context, 10, 10);

Affine:

CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformTranslate(transform, 10, 10);
CGContextConcatCTM(context, transform);

As you can see the first one is more or less just a convenience so you do not need to write so much code.

Upvotes: 2

Related Questions