1. In OC, it is not allowed to directly modify the "member variable" of the "struct attribute" of "object", but allow to modify the "struct property" of "Object"
The member variable 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> Assigning a temporary variable to the object's struct property
2. Need to avoid magic numbers in program development (magic number)
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
3, Frame & bounds & Center
1> Frame can modify the position and size of objects and cannot be scaled under use AutoLayout
2> bounds can modify the size of an object
3> Center can modify the position of an object
4. 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];
Code to participate in the animation
......
Commitanimations, commits and generates animations for all animations after beginanimation
[UIView commitanimations];
5. 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//Displacement
Cgaffinetransformmakescale//Zoom
Cgaffinetransformmakerotation//rotation
2> creating a "transform parameter-based" deformation
Cgaffinetransformtranslate//Displacement
Cgaffinetransformscale//Zoom
Cgaffinetransformrotate//rotation
Add:
In OC, all values associated with an angle are radians, 180°= m_pi, positive numbers are clockwise, negative numbers are rotated counterclockwise
6. Creating controls with code
In OC Development, all operations in storyboard can be implemented in code.
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
7, 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];
8. Lazy Loading Create control
1> Define control Properties, note: The property must be strong.
2> lazy Loading in the getter method of the property, the sample code is as follows:
-(Uiimageview *) icon
{
if (!_icon) {
_icon = [[Uiimageview alloc] init];
......
[Self.view Addsubview:_icon];
}
return _icon;
}
Benefits of using lazy loading:
1> do not have to write the code of the object in the Viewdidload method, the code is more readable
2> each control's getter method is responsible for the respective instantiation process, the code is independent of each other, loosely coupled
9. Using plist file
Purpose of using the Plist file: separating data from code
Loading method:
NSString *path = [[NSBundle mainbundle] pathforresource:@ "name" oftype:@ "plist"];
Nsarray *array= [Nsarray Arraywithcontentsoffile:path];
Hint: The file word usually appears in the method, usually need to pass the full path of the files as parameters
10, the material in images.xcassets
1> only supports images in PNG format
2> images are only instantiated in the way [UIImage imagenamed], but cannot be loaded from bundles
3> at compile time, all files in Images.xcassets will be packaged as assets.car files
11. Uiimageview Sequence Frame animation
========================================
1. Are you animating
[Self.imageview isanimating];
2. Set up an array of pictures
[Self.imageview Setanimationimages:arrayimage];
3. Set the animation duration by default to play 30 pictures per second
[Self.imageview SetAnimationDuration:arrayImage.count * 0.005];
4. Set the number of animations to repeat, default to 0, infinite loop
[Self.imageview setanimationrepeatcount:1];
5. Start animation
[Self.imageview startanimating];
6. Empty the animated array after the animation has finished playing
[Self.imageview performselector: @selector (setanimationimages:) Withobject:nil Afterdelay: Self.imageView.animationDuration];
12, UIImage imagenamed
After the picture is used, it will not be released directly, the specific release time is determined by the system, suitable for small images, commonly used image processing
If you want to release a quick-release picture, you can use [UIImage Imagewithcontentsoffile:path] to instantiate the image
13. Document management [Nsfilemanager Defaultmanager]
Common methods
1> determine if a file exists
-(BOOL) Fileexistsatpath: (NSString *) path;
2> Copy the file from the source path to the destination path
-(BOOL) Copyitematpath: (NSString *) Srcpath Topath: (NSString *) Dstpath Error: (NSERROR *) error ;
3> Delete File
-(BOOL) removeItemAtPath: (NSString *) path error: (NSERROR *) error;
4> Returns a list of files in the specified path
-(Nsarray *) Contentsofdirectoryatpath: (NSString *) path error: (NSERROR *) error;