Cat Learn iOS (i) UI button action Click Transform Move zoom in Zoom out rotation

Source: Internet
Author: User

Not much to say, first piece look effect, cat share, must boutique

This small program mainly realizes the Click arrow key can let the icon move up and down and zoom in and out and rotate the function, click the picture will show another picture.

Click Transform
其实用到了按钮的两个状态,再State Config中的Default还有Highlighted的两个状态下background内容图片的设置

is actually a few states of the button:
Defaults: Default state
Highlighted: highlighted status when clicked
Selected: The state of being selected
Disabled: The state of the time when it cannot be used

Move
-(Ibaction) Move: (UIButton *) button {//Get frameCGRect frame = self.iconButton.frame;//Modify frame properties according to the type of button    Switch(Button.tag) { CaseKmovingdirtop:/** Move Up * /FRAME.ORIGIN.Y-= -; Break; CaseKmovingdirbottom:/** Move Down * /FRAME.ORIGIN.Y + = -; Break; CaseKmovingdirleft:/** Move Left * /Frame.origin.x-= -; Break; CaseKmovingdirright:/** Move Right * /Frame.origin.x + = -; Break; }

This is the main method of implementation, the implementation method is actually many, this method is not the best, can refer to.
Here's what to note:frame
For the class UIView (UIButton and so on are inherited from him, can be seen on the phone display everything is this) has the property on the screen position and so on the most important properties are position and size.
We can enter the source code by holding command + left mouse button (CTRL+COMMAND+J)
By looking at the source code, we found that he defined three:

@property(nonatomicCGRect            frame;@property(nonatomicCGRect            bounds;     @property(nonatomicCGPoint           

Here are:
Frame: main tube position and size (when initialized, other times change to use below two)
Bounds: His dot is 0, main tube size
Center: Mostly point, decide position

Their type is
(struct struct) cgrect

structCGRect {  CGPoint origin;  CGSize size;};

And he includes point and size, of course, these two are also structs, and they know what they're doing. For example, Origin is:
struct CGPoint {/*决定在屏幕上xy坐标*/
CGFloat x;
CGFloat y;
};

And if you look again, CGFloat is a double.

# define CGFLOAT_TYPE double
Zoom Out function
//Zoom in and zoom out- (ibaction) Zoom: (UIButton*) button{//Remove bounds    CGRectBounds = Self. Iconbutton. Bounds;if(Button. Tag){NSLog(@"Zoom In"); Bounds. Size. Width+= -; Bounds. Size. Height+= -; }Else{Bounds. Size. Width-= -; Bounds. Size. Height-= -;NSLog(@"Zoom Out"); }//Add animation    //Animation start[UIViewBeginanimations:NilContextNil];//Set duration[UIViewSetanimationduration:1.0];//zoomed-out bounds back to the original button     Self. Iconbutton. Bounds= bounds;//Submit animations[UIViewCommitanimations];}

Here I do not use a frame to modify, but to use the bounds property, in fact, is essentially the bottom of the cgsize just

Here in order to learn, I added a piece of animated code iOS animation is very human, stronger than Android more than 1:30 points. Be aware that you will have to take a look at the study, do not try, important things will generally be placed on the upper part of the code.

Rotation function
//rotate -(ibaction ) Rotate: (uibutton  *) button{//rotation is mainly used in the angle, OC with radians  cgfloat  angle = (Button.tag )?    M_pi_4:-m_pi_4; self  .iconbutton  .transform  = cgaffinetransformrotate (self     Span class= "hljs-variable" >.iconbutton  .transform , Angle); nslog  (@ "%@" , Nsstringfromcgaffinetransform (self  Span class= "hljs-variable" >.iconbutton  .transform );}  

Well, the basic skills can be done. The rest of you can try it yourself, perfect. But do not slow down the pace of learning oh.
PS1. Need to learn the material can add me znycat
PS2. In order to learn, I will update at least (%d) a week, unknown. Times

Cat Learn iOS (i) UI button action Click Transform Move zoom in Zoom out rotation

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.