Weekly essays-15.9.21 and essay-15.9.21

Source: Internet
Author: User

Weekly essays-15.9.21 and essay-15.9.21
New knowledge point record (15.9.21) 1.WriteToFile:Atomically:

-(BOOL) writeToFile :( NSString *) path atomically :( BOOL) useAuxiliaryFile;

The second parameter indicates:

If YES, the file write Atomicity is ensured. That is to say, a temporary file will be created first until the file content is successfully written and then imported into the target file.

If NO, it is directly written into the target file.

  II. NSerror

The parameters are as follows:

1. Error domain (NSString)

2. Error identification (NSInteger)

3. error message (dictionary)

NSError * error = [NSError errorWithDomain: @ "error domain" code: 400 userInfo: @ {NSLocalizedDescriptionKey: @ "error message"}];

NSLog (@ "% @", error. localizedDescription );

NSLog (@ "% @", error. description );

Note: error. description is not an error message. NSError does not have the description attribute to describe the error message. This is the description of the error object.

Reference

  Iii. ios7 Of Self. view. frame

After ios7.0, if translucent in the navigation bar is YES, that is, translucent, the self. view is always at (0, 0) points in the upper left corner of the screen.

If translucent is NO in the navigation bar, it is not transparent. So self. after a view is loaded, that is, after the viewDidLoad method of the view Controller (note that viewDidLoad is not included), its area does not include the navigation bar, the coordinates are (0, 0) in the lower left corner of the navigation bar. The height is also the screen height minus the navigation bar height and the status bar height.

Note that the loading of self. view is not completed, that is, before self. view is displayed (before viewWillAppear), it is still based on the coordinates (0, 0) in the upper left corner of the screen.

  4.About executing tasks in the main queue column in asynchronous Functions

Dispatch_async (dispatch_get_main_queue (), ^ {

[Self initBaseView];

});

The sample code is as follows:

Add tasks to the main queue and execute them using asynchronous functions. Because the tasks in the main queue column can only be executed in the main thread, so no new threads are opened, the task is executed in a serial manner in the main thread. In this case, the above Code is directly replaced with [self initBaseView]; what is the difference?

The difference is: Add viewDidLoad: There are three pieces of code in the method, from top to bottom in order is a B C. Where B is [self initBaseView];

After the code is run, it is found that the running sequence of the three segments is A, B, and C. There is no problem. However, if B is replaced by an asynchronous function that is executed from the main queue column, the execution order will be A, C, and B.

Because the code above adds the code segment B (Task B) to be executed in the main queue ), the asynchronous function will retrieve Task B from the main queue column after the execution of the task before Task B (that is, the viewDidLoad where Task B is located: function) in the main thread is completed, run the command in the main thread. This is why A and C are executed first. The reason for executing B again. Therefore, B is executed only after the viewDidLoad method is executed.

5. Scale Parameters of the image context Creation Method

Two methods for creating a graphic Context

Method 1: uigraphicsbeginimagecontextwitexceptions (CGSize size, BOOL opaque, CGFloat scale );

Method 2: UIGraphicsBeginImageContext (CGSize size );

 

The three parameters in method 1 are represented in sequence:

Size: the size of the created image context.

Opaque: whether the image context is transparent. NO indicates opacity.

Scale: scale the image (used to adjust the image resolution ).

 

Before understanding the definition, we must first know that for mobile phone screens, we use resolution to measure the definition of the screen. The resolution unit is pixel. For example, the resolution of iPhone 6 is 750*1336 pixels. The screen size we call is 375*668 for iPhone 6, and the Unit is the dot. Therefore, the iPhone 6 screen contains 4 pixels (2*2) at a single point ). This 2 corresponds to the scale attribute of the screen, which can be obtained through [UIScreen mainScreen]. scale.

After understanding the above content, it is not difficult to understand the scale in the method. This scale is the zoom ratio (or the zoom factor) of the obtained image. It determines the resolution of the obtained image. In short, if the scale value is 2, the obtained image has four pixels (two points in length and width ). Generally, we set the scale value to 0, indicating that it is set to the default zoom ratio (the same as the screen). For iPhone 4S, 5, 5 s, and 6 with twice the retain screen, the default scaling ratio is 2. If it is 6 p, the default scaling ratio is 3. Therefore, the scaling ratio is set to 0 or 2, which is the same for iPhone 4S, 5, 5 s, and 6.

There is no scale parameter for method 2. In fact, its default value is 1, not 0. Therefore, the image quality obtained by using this method to create the image context is relatively low (unless iphone4 ). The image quality can be distinguished from the image size. The acquired image is saved to the sandbox, and the image size can be viewed for easy identification.

6. New Method for screenshot capture of ios7.0

-(BOOL) drawViewHierarchyInRect :( CGRect) rect afterScreenUpdates :( BOOL) afterUpdates

This method is used to specify the UIView. by drawing the UIView content to the image context and obtaining the image, the UIView is captured.

Target object: The UIView object to be intercepted

Parameter description:

Rect: The area in the graphic context, not the area of the UIView. Draw the UIView to the area of the graphic context rect.

AfterUpdates: It is unclear. Set to NO to intercept immediately

VII. Pre-compiled output macro definition
#ifdef DEBUG#define DebugLog(format,…)    NSLog(@"{%s,%d}" format, __FUNCTION__,__LINE__,##__VA_ARGS__)#else#define DebugLog(format,…)#endif

System macro introduction:

_ LINE __: the macro is replaced with the current row number during pre-compilation.

_ FUNCTION __: the macro is replaced with the current FUNCTION name during pre-compilation.

_ VA_ARGS __: simply put, it is to put the left... Content to be replaced

# Macro Connector

Reference

8. Operators

&: Bitwise AND

|: By bit or

^: By bit or

~ : Reverse

>>: Right shift

Reference

9. Package the application into ipa

1. First set the running mode to true

2. Xcode top menu -- Product -- Archive

3. Right-click the project and open it in the finder.

4. Right-click and choose "show Package content"> "Products -- Applications" to view a file with a prohibited symbol.

5. Open Itunes and drag it in. In this way, you can find the packaged ipa file in the app bar of Itunes.

Related Article

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.