IOS Development notes-use of the basic UI (4) button (transform attribute) and learning case, iostransform

Source: Internet
Author: User

IOS Development notes-use of the basic UI (4) button (transform attribute) and learning case, iostransform
You can use the transform attribute to modify the displacement (position), scaling, and rotation of the control. It is often used in animation, such as rotation angle, animation scaling, and translation. First, learn some tips developed by xcode: viewcontroll of the story board, which can be directly dragged and copied, the image materials in different projects can also be dragged and copied to each other, but the drag-and-drop copying of images must be performed by option Jian. Otherwise, the image is cut. When we develop similar projects, we don't need to rewrite the interface every time, so we can drag and drop to copy the story board, and drag and drop the picture to hold down the option key and drag it to images. the xcassets directory can be displayed normally and dragged to the storyboard of the new project. The default value is autolayout. Pay attention to the original line! It is best to exit the simulator and xcode and re-open it. In development, if you need to change the control position, size, and rotation, you 'd better use transform to save a lot of trouble. For example, when you encounter autolayout, frame won't work, however, transform can be changed, and the transform attribute modifies the position, size, and rotation of the control. It does not need to calculate the result after deformation. It is an accumulation process relative to itself, you do not need to know the location of the first test and the end of the test, which simplifies the calculation. When encountering new attributes and methods, learn to view the header file and create a transform attribute

CGAffineTransform CGAffineTransformMakeTranslation(CGFloat tx,  CGFloat ty) ;
The AffineTransform class represents 2D affine transformations, which perform linear ing from 2D coordinates to other 2D coordinates
MakeTranslation is used to perform Deformation Based on the initial position of an object! It is not a cumulative deformation. For example:
- (IBAction)move:(UIButton *)button{    self.headImage.transform = CGAffineTransformMakeTranslation(0, -100);}

Click the arrow key and move up only 100 without changing. Click it multiple times, but for the first time, y changes-100.


CGAffineTransform CGAffineTransformMakeScale(CGFloat sx, CGFloat sy);

The scaling and Scaling Functions, sx, and sy respectively manage horizontal and vertical scaling, that is, stretch, or pull width management, and 1.0 does not change, Xiaoyu is 1.0 small, larger than 1.0.

CGAffineTransform CGAffineTransformMakeRotation(CGFloat angle)

The rotation of terms requires making, making changes, apple, and considerate design. Similarly, this setting only changes once. Accumulative changes require the verb methods of three parameters.

(Note: angle is in radians, that is, π. It is not in angle format and is similar to scaling. radians rotate clockwise while negative values rotate counterclockwise)

Overlay a transform (you can change the preceding method to accumulate)

CGAffineTransform CGAffineTransformTranslate(CGAffineTransform t, CGFloat tx, CGFloat ty);

The verb's translate does not need to contain make. There is one more parameter, and the following is also true.

The role is to perform Deformation Based on a specific transform parameter. The actual effect is the accumulation process of displacement.

CGAffineTransform CGAffineTransformScale(CGAffineTransform t, CGFloat sx, CGFloat sy);

At this time, the first parameter is added, and the make parameter is missing, and the verb is used directly. That is, it can be changed all the time, and it is no longer a change to the location of the initial object.

CGAffineTransform CGAffineTransformRotate(CGAffineTransform t, CGFloat angle);

Similarly, if rotate is a verb and make is removed, a parameter must be added later, which is based on a specific transform parameter.

Clear the previously set transform attributes
view.transform = CGAffineTransformIdentity;
Familiar with Apple's development rules! As well as some naming Principles and Methods parameter setting habits.
-(IBAction) zoom :( UIButton *) button {// Add the first and last 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 {// enlarge the button self. 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 {// counter-clockwise 180 degrees, left rotation button self. headImage. transform = CGAffineTransformRotate (self. headImage. transform,-M_PI_2);} [UIView commitAnimations];}

 

Related Article

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.