IOS development-improves APP smoothness (stock quotes) and iosapp
In the past few days, I made an app to view the stock market.
After the completion, when there are many K lines, the app's reaction to kneading and dragging gestures is not smooth,
The main reason is that drawRect: it takes more than 40 ms to work too much, and fps is naturally not high.
Finally, adjust and modify according to the following principles, and improve the smoothness. Most of the drawing time is limited to about 10 ms.
1. Do not implement drawRect whenever possible (each time this method is called, the backing store should be allocated with memory, which consumes a lot of CPU)
2. Avoid consuming a lot of CPU resources in drawRect:
2. Call setNeedsDisplay as few as possible: (called only when the View content changes)
3. Consider using setNeedDisplayInRect:. The smaller the input drawRect: rect, the smaller the stoke and fill time, even if drawRect: is drawn based on The View boundary)
4. make full use of GPU resources and directly set the border, shadow, corner, gradient, and other attributes of the layer. GPU will process these attributes (On the contrary, if the GPU is tight and the CPU is idle, it should be processed by the CPU, can be implemented in drawRect)
5. if you try to enable drawsAsynchronusly when drawing many things to a view, the GPU will plot the View content to the backing store, but the memory will increase when it is enabled, therefore, you need to evaluate the performance changes before and after enabling, and use them with caution.