In iOS, the Core Graphics provides a series of functions that can be transformed on the basis of a transformation, and the following methods are useful if you want to do a transformation that is both scaled and rotated.
Cgaffinetransformscale (Cgaffinetransform T, cgfloat SX, CGFloat sy) --Zoom Out cgaffinetransformrotate ( Cgaffinetransform T, cgfloat angle) --Rotation angle cgaffinetransformtranslate (Cgaffinetransform t, cgfloat tx, cgfloat ty) --Offset: offset tx pixels and Ty pixels in the original position
The specific use is as follows:
1. Create an Cgaffinetransform object
2. Set the process to be processed
3. Assigning values to objects that need to be processed
The code is as follows:
Create Cgaffinetransform object cgaffinetransform transform = cgaffinetransformidentity; Set processing object reduction 50% transform = Cgaffinetransformscale (transform, 0.5, 0.5); Set processing object rotation 30 degree angle Transform = cgaffinetransformrotate (transform, m_pi/180.0 *); Then offset 200 pixels transform = cgaffinetransformtranslate (transform, 0); Assign values to objects that need to be processed: affinetransform self.imageView.layer.affineTransform = transform;
As follows:
Note the place:
Note: The picture is shifted to the right, but not as far as the distance (200 pixels), and it has shifted a bit downward. The reason is that when you do the transformation in order, the result of the previous transformation will affect the subsequent transformations, so the 200-pixel right shift is also rotated by 30 degrees, shrinking by 50%, so it actually moves 100 pixels diagonally.
This means that the order of the transformations affects the final result, that is, the rotation after the pan and after the rotation may be different.
IOS Hybrid Transform rotation cgaffinetransform