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];