Tips for troubleshooting pages in iOS (very common)

Source: Internet
Author: User

1. Why does the page lag?

In the development we often encounter the layout of the more complex cells, when sliding will lead to the interface is not smooth, the phenomenon of lag, this is due to CPU computing and GPU rendering, not in time to exchange data lost frames caused by the result.
2. Common Solutions1). Uiimageview try to set as opaque
    • Opque try to set to Yes

When Uiimageview's opque is set to Yes, its Alpha property is not valid, and Uiimageview's translucency depends on its translucent image or the layer view of the Uiimageview itself's background color compositing.

If the picture is not translucent, the layer's blend will not be triggered, and the entire layer will be opaque.

If the superimposed picture appears translucent, it immediately triggers the layer's blend operation, and the entire layer is opaque.

    • Background color set to alpha value as much as 1

Alpha compositing is triggered when the alpha of a layer is different from its Superview background color alpha, which is a seemingly simple operation that consumes CPU performance.

2). Background color settings for UIView
    • The background color of the UIView is not set to Clearcolor, which also triggers the alpha overlay, which is very performance-intensive when the uitableview is sliding. The background color of the child view is set to the background color of its superview as much as possible so that the blend is not triggered when the layer is synthesized.

    • It is best not to use a picture with an alpha channel, and if there is Alpha, try to get the UI designer to cancel the alpha channel.


3). The cell on the layer as far as possible to avoid using rounded corners
    • In the work of the sliding interface we will often encounter the cell line set head to fillet and other requirements, this time we try layder.cornerRadius to avoid the use, as this will trigger off-screen rendering. Off-screen rendering is time consuming.

      Off-Screen rendering: is a render buffer in the GPU render area, and the graphical images of all the displays we use are rendered on the GPU and then displayed on the screen. GPU is responsible for rendering will put the rendered graphics into the buffer and then the CPU will send a vertical signal to display to the screen.

    • If you want to use rounded corners, we can set it to layer.shouldRasterize = YES , in fact, this setting is triggered rasterization, can greatly improve the performance of rendering. My understanding of rasterization is similar to the cell reuse mechanism.

      Rasterization: Put the first rendered layer into the buffer, then the next time you do not need to be off-screen rendering directly can be taken from the buffer to use.

4). Optimize how images are loaded

There are two ways to load a picture:

Uiimageview *image = [Uiimageview imageview:@ "1.png"];

Uiimageview *image = [Uiimageview imagewithcontentoffile:@ "1.png"];

Two different ways to load pictures:

    • The first: We can use this method to load images when we often need this image and are just small graphs.

      This way is to cache the image in the image buffer, when we use the image by the name of the way to find the image in the buffer memory address.

      When we use a lot of pictures, the system will open up a lot of memory to store pictures, so QQ, we will often go to clear cache operation.

    • The second: When we use a large map of the project and the use of a few or even 1 times, we prefer to load the image in this way, when the use of the picture will immediately discard the release of resources, so there is no burden on performance.

5). Delay loading of images as much as possible
    • When we are sliding the page, especially for that kind of layout particularly complex cell, slide the time do not load the picture, when the slide stopped when the picture loading.

      We all know that whether it is UITableView or Uiscrollview in the rolling time need to show things are through Runloop to get.

      Runloop will be in Nsrunlooptrackingmode mode when scrolling, we can get through a main thread queue Dispatch_ After or Selfperformselector settings runloop mode is Nsdefaultrunloopmode mode, you can stop scrolling and reload the picture.

      注:其实严格意义上selfPerformSelector的事件就是在主线程队列中等待。

    • Priority Load Concept

      With the idea of a priority load, the first part is shown, and when you slide it, load the following part so that it stays smooth.

6). Avoid blocking the main thread
    • Let the picture drawing, the picture download, the object creation, the text rendering and so on these time-consuming operation take the child thread asynchronously the way to deal with, for layer and the UI operation to have in the main thread inside, can only think of ways to optimize.
7). Xib, StoryBoard, pure code issues
    • Apple's launch of storyboard really saves developers a lot of time and improves development efficiency, but for that
      Complex sliding interface, the use of storyboard is very resource-intensive, can not be trusted to try to test performance tools Timeprofie See CPU Percentage of performance, its CPU resources far greater than the pure code layout.


Tips for troubleshooting pages in iOS (very common)

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.