Example summary of affine transformations for iOS development

Source: Internet
Author: User

First, translation

Now let's take a look at the translation of Cgaffinetransform, and when we use cgaffinetransform to translate, we should pay attention to the transformation of the coordinate system. Below is the coordinate system for the UI layout, which is the coordinate system of the iOS screen. The upper-left corner is the origin, the x-axis is right, the left is negative, the y-axis is negative, and the next is positive. Below is the screen coordinate system of the iphone. Translation is also the lower coordinate system structure.

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/545446/201702/545446-20170209102247197-1807918027. PNG "width=" 319 "height=" 225 "style=" margin:0px;padding:0px;border:none; "/>

Below is the effect of panning the ImageView. Use two sliders to control left and right movement and move up and down. The specific operating effect is shown below.

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/545446/201702/545446-20170209103348776-1339597598. GIF "width=" 290 "height=" 522 "style=" margin:0px;padding:0px;border:none; "/>

The code that controls panning is also relatively straightforward, as shown below. When the x parameter is positive, it moves to the right and X is negative, moving to the left. While the parameter y is positive, it moves downward and Y is negative when it moves upwards. The specific code looks like this:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/545446/201702/545446-20170209104004119-1068245650. PNG "width=" 643 "height=" "style=" margin:0px;padding:0px;border:none; "/>

Second, zoom

After the panning, let's take a look at the scaling of affine transformations. It is also easier to zoom in and out with Cgaffinetransform, which is the effect of scaling the imageview. In the process of zooming, it is divided into X-direction scaling and Y-direction scaling. X and y represent multiples of scaling on the X and Y axes, and if x or Y is negative, then the corresponding view is flipped and scaled, and the effect is as follows.

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/545446/201702/545446-20170209105326666-900845186. GIF "width=" 275 "height=" 495 "style=" margin:0px;padding:0px;border:none; "/>

The above effect is also relatively simple, the code on the following line, as shown below, X represents the scale on the x-axis, y represents the amount of scaling on the y-axis.

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/545446/201702/545446-20170209105528979-1921843562. PNG "width=" 622 "height=" "style=" margin:0px;padding:0px;border:none; "/>

Third, rotation

The next step is to talk about the rotation of the cgaffinetransform, straight to the subject, below the running results. Rotation is rotated in radians, one lap is 0-2∏, and if the radian is positive, it rotates clockwise, or counterclockwise if the arc is negative. The results of the specific operation are as follows:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/545446/201702/545446-20170209111138635-2030447040. GIF "width=" 248 "height=" 446 "style=" margin:0px;padding:0px;border:none; "/>

The code to achieve the above effect is also relatively simple, the specific code is as follows:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/545446/201702/545446-20170209111441979-1767961031. PNG "width=" 729 "height=" style= "margin:0px;padding:0px;border:none;"/>


Example summary of affine transformations for iOS development

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.