Search code examples
iosobjective-crotationscalecgaffinetransform

CGAffineTransformMakeRotation and CGAffineTransformMakeScale


How come only one of the above works in code?

Currently I am using the following...

image.transform = CGAffineTransformMakeRotation(M_PI/2.5);
image.transform = CGAffineTransformMakeScale(1.25, 1.25);

And my image is scaled to 125% like the second line says, however it is not rotate at all.

When I flip the code around to say...

image.transform = CGAffineTransformMakeScale(1.25, 1.25);
image.transform = CGAffineTransformMakeRotation(M_PI/2.5);

My image is rotated but not scaled...

Is there a way to use both of these in the same code?

I have these in my viewDidLoad method. Can anyone help me?

Thanks!


Solution

  • The second one should not use the Make rendition of the function. Thus you should, for example either:

    CGAffineTransform transform = CGAffineTransformMakeScale(1.25, 1.25);
    image.transform = CGAffineTransformRotate(transform, M_PI/2.5);
    

    or

    CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2.5);
    image.transform = CGAffineTransformScale(transform, 1.25, 1.25);
    

    Contrast the Creating an Affine Transformation Matrix functions with the Modifying Affine Transformations functions.