IOS Hybrid Transform rotation cgaffinetransform

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.