((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
The CGAffineTransform type provides functions for creating, concatenating, and applying affine transformations. Affine transforms are represented by a 3 by 3 matrix: Because the third column is always (0,0,1) , the CGAffineTransform data structure contains values for only the first two columns.
Basic Swift Code for iOS AppsStep 1 − Open Xcode→SingleViewApplication→name it RotateImage. Step 2 − Open Main. storyboard, add UIImageView and add 2 buttons as shown below name them ROTATE BY 90 DEGREES AND ROTATE BY 45 DEGREES.
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.
From the Apple Documentation:
CGAffineTransformConcat Returns an affine transformation matrix constructed by combining two existing affine transforms.
CGAffineTransform CGAffineTransformConcat (
CGAffineTransform t1,
CGAffineTransform t2
);
Parameters t1 The first affine transform.
t2 The second affine transform. This affine transform is concatenated to the first affine transform.
Return Value A new affine transformation matrix. That is, t’ = t1*t2.
Discussion Concatenation combines two affine transformation matrices by multiplying them together. You might perform several concatenations in order to create a single affine transform that contains the cumulative effects of several transformations.
Note that matrix operations are not commutative—the order in which you concatenate matrices is important. That is, the result of multiplying matrix t1 by matrix t2 does not necessarily equal the result of multiplying matrix t2 by matrix t1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With