IOS_2 _ button controls Object Deformation

Source: Internet
Author: User

IOS_2 _ button controls Object Deformation

BeyondViewController. h

//// BeyondViewController. h // 02 _ button controls Object Deformation // Created by beyond on 14-7-21. // Copyright (c) 2014 com. beyond. all rights reserved. // # import
 
  
@ Interface BeyondViewController: UIViewController // The Controller member remembers the Avatar button on the interface @ property (weak, nonatomic) IBOutlet UIButton * headBtn; // The button controls the upper, lower, left, and right movement of the head button-(IBAction) btnClick :( UIButton *) sender;-(IBAction) AffineTransform :( UIButton *) sender;-(IBAction) reset :( UIButton *) sender; @ end
 



BeyondViewController. m

//// BeyondViewController. m // 02 _ button controls Object Deformation /// Created by beyond on 14-7-21. // Copyright (c) 2014 com. beyond. all rights reserved. // # import "BeyondViewController. h "# define kDelta 20 const int DELTA = 50; @ interface BeyondViewController () {// member variable of the least left rotation method remembers that radians can accumulate CGFloat _ angel; // The member remembers the default frame CGRect _ headBtnFrame of headBtn;} @ end @ implementation BeyondViewController-(void) viewDidLoad {[super viewDidLoad]; // when a view is loaded, use a member to remember the initial position _ headBtnFrame = _ headBtn. frame; // call the custom method. The Code creates a buttuon [self addButtionByCoding]; [self addTextFieldByCoding];} # The pragma mark-button controls the top, bottom, left, and right movement of the head button-(void) moveByFrame :( UIButton *) sender {// class method of UIView to achieve the animation effect (start animation) [UIView beginAnimations: nil context: nil]; // The default animation duration is 0.2 [UIView setAnimationDuration: 1]; // the following three steps are the OC standard code, because OC does not allow users to directly repair the value of the members of the struct attribute in this object, the temporary struct variable CGRect frame = self must be passed. headBtn. frame; // if the number is the same, it can be extracted as: 1, variable; 2, macro; 3, const int // CGFloat delta = 50; // # define kDelta 50 // const int DELTA = 50; int tag = [sender tag]; switch (tag) {case 1: frame. origin. y-= kDelta; break; case 2: frame. origin. x + = kDelta; break; case 3: frame. origin. y + = kDelta; break; case 4: frame. origin. x-= kDelta; break; default: break;} self. headBtn. frame = frame; // The class method of UIView to achieve the animation effect (end animation) [UIView commitAnimations];}-(IBAction) btnClick :( UIButton *) sender {[self animateWithBlock: ^ {// the following three steps are the OC standard code, because OC does not allow users to directly repair the value of the members of the struct attribute in this object, the temporary struct variable CGPoint center = self. headBtn. center; // if the numbers are the same, they can be extracted as: 1, variable; 2, macro; 3, const int // CGFloat delta = 50; // # define kDelta 50 // const int DELTA = 50; int tag = [sender tag]; switch (tag) {case 1: center. y-= kDelta; break; case 2: center. x + = kDelta; break; case 3: center. y + = kDelta; break; case 4: center. x-= kDelta; break; default: break;} self. headBtn. center = center ;}] ;}# pragma mark-button controls the Left and Right rotation of the head button to zoom in and out-(IBAction) AffineTransform :( UIButton *) sender {// The class method of UIView to achieve the animation effect (start animation) [UIView beginAnimations: nil context: nil]; // The default animation duration is 0.2 [UIView setAnimationDuration: 1]; int tag = [sender tag]; switch (tag) {case 11: // _ angel-= M_PI_4; // The clockwise rotation is positive, use the radian M_PI_4 to rotate 45 degrees clockwise // _ headBtn. transform = CGAffineTransformMakeRotation (_ angel); // CGAffineTransformRotate: returns a new struct, which is a new struct _ headBtn with a certain radian rotation based on the original struct. transform = CGAffineTransformRotate (_ headBtn. transform,-M_PI_4); break; case 12: // _ angel + = M_PI_4; // rotate clockwise to the positive direction. Use the radian M_PI_4 to rotate 45 degrees clockwise. // _ headBtn. transform = CGAffineTransformMakeRotation (_ angel); // CGAffineTransformRotate: returns a new struct, which is a new struct _ headBtn with a certain radian rotation based on the original struct. transform = CGAffineTransformRotate (_ headBtn. transform, M_PI_4); break; case 13: // zoom out // _ headBtn. transform = CGAffineTransformMakeScale (0.5, 0.5); _ headBtn. transform = CGAffineTransformScale (_ headBtn. transform, 0.8, 0.8); break; case 14: // enlarge // _ headBtn. transform = CGAffineTransformMakeScale (1.5, 1.5); _ headBtn. transform = CGAffineTransformScale (_ headBtn. transform, 1.2, 1.2); break; case 0: // when you click headBtn, clear and restore to the default status _ headBtn. transform = CGAffineTransformIdentity; _ headBtn. frame = _ headBtnFrame; break; default: break;} // The class method of UIView to achieve the animation effect (end animation) [UIView commitAnimations];} # pragma mark-encapsulate code by block // void (^ myBlock) (); void (^ myBlock) () = ^ {NSLog (@ "beyond ");}; // There is a problem when calling block () Manually-(void) animateWithBlock :( void (^) () block {// The class method of UIView to achieve the animation effect (start animation) [UIView beginAnimations: nil context: nil]; // The default animation duration is 0.2 [UIView setAnimationDuration: 1]; block (); // The class and method of UIView to achieve the animation effect (end animation) [UIView commitAnimations];}-(IBAction) reset :( UIButton *) sender {[self animateWithBlock: ^ {// when you click it, it is cleared and restored to the default status _ headBtn. transform = CGAffineTransformIdentity; _ headBtn. frame = _ headBtnFrame;}];}-(void) addButtionByCoding {// 1. Use the class method to create the button instance UIButton * button = [[UIButton alloc] init]; // 2. Set the button details. frame = CGRectMake (0, 0,100,100); // normal State [button setTitle: @ "normal" forState: UIControlStateNormal]; [button setTitleColor: [UIColor redColor] forState: UIControlStateNormal]; // [button setImage: [UIImage imageNamed: @ "btn_01.png"] forState: UIControlStateNormal]; [button failed: [UIImage imageNamed: @ "btn_01.png"] forState: UIControlStateNormal]; // click the highlighted State [button setTitle: @ "highlighted" forState: UIControlStateHighlighted]; [button setTitleColor: [UIColor blueColor] forState: UIControlStateNormal]; // [button setImage: [UIImage imageNamed: @ "btn_02.png"] forState: UIControlStateHighlighted]; [button setBackgroundImage: [UIImage imageNamed: @ "btn_02.png"] forState: Success]; // Add the click event [button addTarget: self action: @ selector (codeBtnClick :) forControlEvents: UIControlEventTouchUpInside] for the button; // 3, add the button to the view of the current controller [self. view addSubview: button] ;}// Click Event of the code creation button-(void) codeBtnClick :( UIButton *) sender {NSLog (@ "% @", sender ); NSLog (@ "% p", sender);} // code to create a text input box-(void) addTextFieldByCoding {// 1, create control UITextField * textField = [[UITextField alloc] init]; // 2. Control details textField. frame = CGRectMake (100, 0,100,100); textField. backgroundColor = [UIColor grayColor]; // system font size textField. font = [UIFont systemFontOfSize: 20]; textField. font = [UIFont boldSystemFontOfSize: 30]; // center display CGFloat x = self. view. frame. size. width * 0.5; CGFloat y = self. view. frame. size. height * 0.5; // textField. center = CGPointMake (x, y); // the following three steps are the OC standard code, because OC does not allow users to directly repair the value of the members of the struct attribute in this object, the temporary struct variable CGPoint center = textField to be passed. center; center. x = x; center. y = y; textField. center = center; // 3. Add the control to view [self. view addSubview: textField];} @ end


















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.