How do I use CGAffineTransformMakeScale and Rotation at once?

quantumpotato picture quantumpotato · Dec 13, 2009 · Viewed 20.6k times · Source
((UIImageView*)[dsry objectAtIndex:0]).transform = CGAffineTransformMakeRotation(1.57*2);
((UIImageView*)[dsry objectAtIndex:0]).transform = CGAffineTransformMakeScale(.5,.5);

Just one of these works at a time. How can I save a transformation and then apply another? Cheers

Answer

Brad Larson picture Brad Larson · Dec 13, 2009

To expand upon what Peter said, you would want to use code like the following:

CGAffineTransform newTransform;
newTransform = CGAffineTransformMakeRotation(1.57*2);
((UIImageView*)[dsry objectAtIndex:0]).transform = CGAffineTransformScale(newTransform,.5,.5);

The CGAffineTransformMake... functions create new transforms from scratch, where the others concatenate transforms. Views and layers can only have one transform applied to them at a time, so this is how you create multiple scaling, rotation, and translation effects on a view at once.

You do need to be careful of the order in which transforms are concatenated in order to achieve the correct effect.