1. Parameters of the Ibaction
========================================
-(Ibaction) Left: (UIButton *) button
1> in OC, the first parameter of the most control listener method is the control itself
2> parameter type is ID when default line is connected
3> If you want to use the control in a listening method, you can modify the parameter type of the listening method when you connect or connect.
2. Modifying the structure members of an object
========================================
In OC, you are not allowed to directly modify the members of the struct properties of the object, but allow you to modify the struct properties of the object
When an object has a struct attribute, you cannot directly modify the members of the struct, but you can modify the structure of the body
// Here's a brief explanation. UIButton *btn == CGRectMake (x,y,width,height); // Assigning values to the structure properties of BTN Btn.frame = rect; // You cannot assign a value directly to a member of a struct in an object property /* btn.frame.orign.x =; It is wrong to write this Btn.frame.orgin = Cgpointmake (x, y);//Ibid. * /
The member methods for modifying struct properties are as follows:
1> using temporary variables to record the structure properties of an object
2> modifying the properties of a temporary variable
3> to reset temporary variables to the structure properties of an object
3. In the program development need to avoid magic numbers (magic number): Some inexplicable numbers, only self-understanding, other programmers can not understand
For example:
roughly abbreviated: typedefenum{Mans=1, Woman} Mysex;//The following is the magic number, only their own to understand, to avoid magic numbers, change the 1 to man,2 into a women so that the other program apes can readSwitch(pass an integer value) { Case 1: NSLog (@"Men"); Break; Case 2: NSLog (@"Women"); Break; default: NSLog (@"Gender Unknown"); Break; }
========================================
Use enum types to avoid magic numbers in your program
The 1> enumeration type is essentially an integer that is used to replace the magic number
2> enumeration type, after the first integer is specified, the subsequent number is incremented
4. Frame & Bounds & Center
========================================
1> Frame can modify the position and size of the object----------origin is the point in the upper-left corner of the parent class
2> bounds can modify the object's dimensions-------origin is the point in the upper-left corner
3> Center can modify the position of an object
5. End-to-end animations
========================================
// beginanimations indicates that subsequent code will "participate in" the animation [UIView Beginanimations:nil context:nil]; // setanimationduration used to specify the duration of the animation [UIView setanimationduration:2.0= rect; // Commitanimations, commits and generates animations for all animations after BeginAnimation [UIView commitanimations];
using block animations for end-to-end animations//2.0 for animation execution time [UIView animatewithduration:2.0 animations:^{ // 1. Animation becomes smaller self.iconView.frame = cgrectmake. // 2. Mask transparent, invisible 0.0f; }];
[UIView beginanimations:nil Context:nil] [UIView setanimationduration:2.0]; // the method to execute after the animation finishes (using a proxy) // let the controller be the agent and let him call the specified method [UIView setanimationdidstopselector: @selector (method name)];
[UIView commitanimations];
// using fast code to implement the animation after the end of method 1.0 means that the animation execution time is 1 seconds
[UIView animatewithduration:1.0 animations:^{
The animation code to execute
}completion:^ (BOOL finished) {
Code to execute after the animation executes
}];
6. Transform Properties
========================================
In OC, you can modify the translation, scaling, and rotation angles of an object by using the Transform property
Common methods for creating transform structures are divided into two main categories
1> creating a "control-based initial position" deformation
Cgaffinetransformmaketranslation//Translate, pass parameters are translation length, not multiples
Cgaffinetransformmakescale//telescopic, transmission parameters are scaling multiples
Cgaffinetransformmakerotation
2> creating a "transform parameter-based" deformation
Cgaffinetransformtranslate
Cgaffinetransformscale
Cgaffinetransformrotate
Add:
in OC, all values associated with the angle are in radians, 180°= m_pi
positive number indicates clockwise rotation
negative number indicates counterclockwise rotation
Tip: Because the Transform property can be superimposed on the last state of the control, for example, rotate and then pan
Therefore, in the actual animation development, when it involves the position, the size deformation effect, mostly modifies the control's Transform property,
Instead of frame, bounds, center
7. Creating controls with code
========================================
In OC Development, all operations in storyboard can be implemented in code,programmers must be proficient in the ability of the code layout interface!
To create a control using code, follow these steps:
1> creating an object using the control's corresponding class
2> Setting Object properties: Frame\color\text\image\backgroundimage ...
3> [Self.view addsubview:btn]; Adding controls to the view
The sample code for setting the control listener method is as follows:
[Btn addtarget:self Action: @selector (click:) forcontrolevents:uicontroleventtouchupinside];
Tips:
The 1> Addtarget method is defined in the Uicontrol class, which means that you can add a listening method to all objects that inherit from the Uicontrol class
The first parameter of the 2> listener method is the object itself
The second parameter of the 3> listener method is the event that listens to the control
8. Viewdidload
========================================
Viewdidload is the method that is called after the view is loaded, typically performing the initialization of the view controller in this method
In the Viewdidload method, be sure not to forget to invoke the parent class's method implementation!
[Super Viewdidload];