Ios drag controls 1

Source: Internet
Author: User

Ios drag controls 1

1. IBAction:

1> ensure that the method can be connected

2> equivalent to void

-(IBAction)


2. IBOutlet:

1> ensure that attributes can be connected

@ Property (weak, nonatomic) IBOutlet



3. Common Errors

SetValue: forUndefinedKey:]: this class is not key value coding

The cause of the error is that the connection is faulty.


4. Some suggestions from Xcode5

Declare some methods and attributes used for connection in the class extension of the. m file.

CGRect tempBounds = self. head. bounds; // 2. change the temporary attribute tempBounds. size. width + = 20; tempBounds. size. height + = 20; // 3. overwrite the original self. head. bounds = tempBounds;


5. frame \ center \ bounds

1> frame: the position and size can be modified.

You cannot use the dot syntax to directly modify the value of the frame attribute.

  CGRect btnFrame = self.controlName.frame;  btnFrame.origin.y -= 10;  self.controlName.frame = btnFrame;

2> center: the location can be modified.

You cannot use the dot syntax to directly modify the value of the center attribute.

CGPoint tempCenter = self.head.center;tempCenter.x += 10;self.head.center = tempCenter;


3> bounds: can modify the size (x \ y is generally 0)

You cannot use the dot syntax to directly modify the bounds attribute value.

 CGRect tempBounds = self.head.bounds; tempBounds.size.width += 20; self.head.bounds = tempBounds;



6. automatically generate connection information

Drag control



7. dynamically create controls using code

-(Void) viewDidLoad {[super viewDidLoad]; NSLog (@ "----- viewDidLoad"); // Add // 1. create button UIButton * btn = [[UIButton alloc] init]; // 2. add button [self. view addSubview: btn]; // 3. set frame btn. frame = CGRectMake (100,100,100,100); // 4. set background color btn. backgroundColor = [UIColor blueColor]; // UIImage * image = [UIImage imageNamed: @ "btn_01"]; // [btn setBackgroundImage: image forState: uicontrolstate];}


8. Simple over-Animation


// 0. start the animation [UIView beginAnimations: nil context: nil]; // The animation lasts for 2 seconds [UIView setAnimationDuration: 2.0]; // 1. retrieve the original attribute CGRect tempBounds = self. head. bounds; // 2. change the temporary attribute tempBounds. size. width + = 50; tempBounds. size. height + = 50; // 3. overwrite the original self. head. bounds = tempBounds; // 4. submit an animation [UIView commitAnimations];




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.