IOS Performance Optimization Analysis
First, you must familiarize yourself with several concepts.
- What is the difference between PNG and JPG?
Png images have alpha channels, while jpeg images do not. Png lossless compression, jpeg allows you to choose a compression quality of 0-100%. If the alpha channel is required (transparent), only png format is required.
- CPU and GPU
- If you want to see the difference between the two, you must first understand the underlying hierarchical structure principle behind the iOS view. The bottom line is the hardware layer, which consists of GPU and CPU. We often mention that hardware acceleration actually refers to OpenGL. Core Animation/UIKit is based on GPU to implement computer graphics synthesis and drawing. Until now, the hardware acceleration capability on iOS is still far ahead of android. The latter relies on CPU rendering, and the vast majority of animation implementations will make people feel stuck.
Architecture and principle of iOS view rendering
- Many basic behaviors of the UIView class depend heavily on another 2. object. Behind each view object in UIKit is a CoreAnimation layer object, which is an instance of the CALayer class that provides basic support for rendering, layout, synthesis, and animation of View content.
- Unlike Mac OS, ios integrates CoreAnimation into the core of view rendering. Because the SDK provides transparent interfaces, developers do not have to worry about and directly access CoreAnimation in most cases. However, to implement complicated rendering and animation, you need to use the CoreAnimation interface.
- CoreAnimation's basic CoreAnimation uses hardware acceleration and Architecture Optimization to achieve fast rendering and real-time animation. When the drawRect method of a view is called for the first time, the layer captures the drawn result to a bitmap and tries to use this bitmap during subsequent re-painting to avoid overhead. CoreAnimation stores the layers associated with the view object in the hierarchy of the layer tree. You can add special layers to the layer tree to achieve different effects. Layer objects are the driving force behind IOS rendering and layout systems. Most view attributes are actually a thin encapsulation of layer object attributes. Indicates the current status when the layer is displayed to the user. Rendering tree: runs on a separate thread and does not affect the main app thread to achieve animation rendering.
How to optimize view loading speed
Offscreen drawing)
Offscreen drawing refers to the drawing of the GPU on the current screen, while the other side uses the CPU to generate image information before the screen is processed. In iOS, the off-screen rendering is automatically triggered in the following situations:
1. core Graphics (any class starting with CG) 2. in the drawRect method, or even the empty method is implemented. 3. all shouldRasterize attributes are the YES CALayers object 4. all CALayers objects with masks (setMasksToBounds) and dynamic shadows (setShadow *) 5. draw all text, including CoreText6.Group opacity (UIViewGroupOpacity)
Use pre-rendering to accelerate image display on iOS devices
When the image is displayed, decompression and re-sampling consume a lot of CPU time. If the image is drawn in a bitmap context in advance, the image is cached, you can save the effort. To this end, some lovely people dedicated to the experiment
Let's take a look at the specific lab examples in http://mobile.51cto.com/iphone-279459.htm
Reference: http://www.taofengping.com/2013/05/17/designing-for-ios-graphics-performance/#.U4l3eFFvB50
Http://mobile.51cto.com/iphone-279459.htm