IOS Development Notes-using the basic UI (4) button (transform property) and learning case

Source: Internet
Author: User

The Transform property allows you to modify the displacement (position), scale, and rotation of the control. Often used in animations, such as rotation angle, animation scaling, panning, etc.learn a few Xcode development tips first:the Viewcontroll of the storyboard can be directly dragged and copied, and the picture material in different projects can be dragged and copied using each other, but the drag-and-drop copy of the picture is done by option, otherwise it is cut. Then we in the development of some similar projects, do not have to rewrite the interface every time, then you can drag and drop the copy of the storyboard, the picture drag to hold the option key while dragging to the Images.xcassets directory can be normal explicit, and dragged to the new project storyboard, the default is AutoLayout, but also pay attention to the original connection! It is best to exit the simulator and Xcode and then reopen it. in development, if you need to change the position, size, rotation of the control, it is best to use transform, can save a lot of trouble, such as when encountering AutoLayout, frame is not, but transform can change, and The Transform property modifies the position, size, rotation of the control, does not need to calculate the result after the deformation, it is a relative to its own accumulation process, do not need to know the initial position and the end of the position, simplifying a lot of computational capacity. encounter new properties and methods, learn to view header filesCreate a Transform property
Cgaffinetransform cgaffinetransformmaketranslation (cgfloat tx,  cgfloat ty);
The AffineTransform class represents a 2D affine transformation that performs a linear mapping from 2D coordinates to other 2D coordinates
Maketranslation (noun's translation) function is: the deformation based on the initial position of the object! Not a cumulative deformation. Such as:
-(Ibaction) Move: (UIButton *) button{    = cgaffinetransformmaketranslation (0,-  );}

Click the arrow keys, only move up 100 no longer change, click multiple times, only the first time y change-100.


Cgaffinetransform Cgaffinetransformmakescale (cgfloat sx, CGFloat sy);

Deformation, scaling function, SX, and SY respectively management of the horizontal and vertical scaling, that is, elongated, or pull the width of the management, and 1.0 does not change, small Jade 1.0 small, greater than 1.0 to become larger.

Cgaffinetransform cgaffinetransformmakerotation (cgfloat angle)

The rotation of nouns, make, change, apple and considerate design. Similarly, such a setting changes only once. The cumulative change requires a verb method of three parameters.

(Note: The angle is a radian, that is, π, not angular, and similar to scaling, the radian is positive is clockwise rotation, negative numbers are counterclockwise rotation)

overlay on the basis of a transform (can change the above method to become cumulative)

Cgaffinetransform cgaffinetransformtranslate (Cgaffinetransform t, cgfloat tx, cgfloat ty);

The translate of a verb, with no make, more than one parameter, is also the case below.

The effect is a deformation that is done on the basis of a transform parameter, and the actual effect is a cumulative process of displacement.

Cgaffinetransform Cgaffinetransformscale (Cgaffinetransform T, cgfloat SX, CGFloat sy);

At this time also the first parameter, less make, the direct verb. Then it is possible to change all the time, no longer relative to the position of the preliminary object.

Cgaffinetransform cgaffinetransformrotate (Cgaffinetransform t, cgfloat angle);

Similarly, rotate is a verb, remove make, then there must be more than one parameter, relative to the basis of a transform parameter to change.

clears the previously set transform property
View.transform = cgaffinetransformidentity;
familiar with the Apple development rules! As well as some naming principles and methods of setting the habit of the parameters.
-(ibaction) Zoom: (UIButton *) button {//plus a tail-end animation[UIView Beginanimations:nil Context:nil]; [UIView setanimationduration:2.0]; //Zoom Out button    if(0==button.tag) {self.headImage.transform= Cgaffinetransformscale (Self.headImage.transform,0.5,0.5); }    Else    {        //Zoom In buttonSelf.headImage.transform = Cgaffinetransformscale (Self.headImage.transform,1.5,1.5); } [UIView commitanimations];}-(ibaction) Rotate: (UIButton *button {[UIView beginanimations:nil context:nil]; [UIView setanimationduration:2.0]; //clockwise 180 degrees, right rotation button    if(1==button.tag) {self.headImage.transform=cgaffinetransformrotate (Self.headImage.transform, m_pi_2); }    Else    {        //Counterclockwise 180 degrees, left rotation buttonSelf.headImage.transform = Cgaffinetransformrotate (Self.headImage.transform,-m_pi_2); } [UIView commitanimations];}

IOS Development Notes-using the basic UI (4) button (transform property) and learning case

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.