IOS Slide Performance optimization

Source: Internet
Author: User

IOS Slide Performance optimization
Directory
    • One, reduce the layer's blend operation
      • 1. UIView background color To avoid the use of Clearcolor
      • 2. Control map avoid using images with alpha
      • 3. Avoid translucency when using Uiimageview
    • Ii. appropriate use of rasterize
    • Third, avoid resampling of picture resources
    • Summarize
    • More Resources
One, reduce the layer's blend operation

Display a translucent view, the device will be the current layer and background layer alpha overlay, this is a very expensive thing. If each frame in the animation is superimposed, the performance loss is very serious.

1. UIView background color To avoid the use of Clearcolor
    • UIView remember to set the same color as Superview

Although the action is small, the effect is good
Especially if you need to slide the scene

2. Control map avoid using images with alpha
    • Visually-given textures are best without alpha channels
    • If Alpha must be used, the active de-alpha, advance and background colors are synthesized into pictures without alpha

Image compositing for the same scene only needs to be done once
One-time synthesis, long-term use

3. Avoid translucency when using Uiimageview

Disable alpha blending except where needed. Unless you is intentionally working with images that contain transparency (drawing UI elements, for example), you should Generally mark the view as opaque by checking opaque checkboxes in the attributes inspector, or setting the Opaque property On the view itself.

The translucency of the Uiimageview depends on the following:

    • The picture shown
    • The value of the opaque property of the view
    • The alpha value of the view
    • Background color of view

An opaque view are expected to fill their bounds with entirely opaque content-that are, the content should has an alpha value of 1.0. If The view is opaque and either does isn't fill its bounds or contains wholly or partially transparent content, the results is unpredictable. You should always set the value of this property to NO if the view is fully or partially transparent.

The rules are as follows:

    • When the Opaque property is yes, the Alpha property of the ImageView is ignored and the layer is translucent depending on the result of the overlay of the background color of the picture and the ImageView itself.

      • If the overlay result graph is all opaque, the layer is opaque and does not trigger the blend operation.

      • If semitransparent areas appear in the overlay results, the entire layer becomes opaque and the blend action is triggered.

    • If the opaque property is no, the layer is translucent depending on the multiplied overlay result of the picture and ImageView.

Simple to understand, if possible:
    • Set Opaque to Yes
    • Background color set to a color that does not contain alpha
    • The alpha value is also preferably 1 (opaque).
Applicable scenarios
    • General optimization rules that do not cause side effects
Ii. appropriate use of rasterize

For cells with relatively fixed content, it is advisable to use rasterization to allow the core animation framework to help us to complete the blending of layers, generate a static graph, and optimize the frame rate.

Applicable scenarios
    • UITableView & Uicollectionview & Uiscrollview cells with infrequent changes in content

Note: This optimization requires profile and is tuned using the "colorhitsgreenandmissesred" tool in the core animation tool
If used improperly, it may backfire

Third, avoid resampling of picture resources

Image views can perform, operations that is relatively expensive performance-wise:scaling the image and Alpha Composi Ting the image with lower layers.

To reduce the resampling of image resources is a time-consuming process, involving interpolation algorithm, with bilinear interpolation as an example, each interpolation point needs to use the surrounding four points of the pixel value, the calculation is visible.

A large image is set directly for Uiimageview, which takes time and memory when the main thread completes the resampling process in the actual presentation.

How to avoid it?
    • Network Picture Resources

      • When the interface is requested, the service side returns dimensions as close to the displayed picture resources as possible based on the scene.

      This saves both traffic and the time it takes to resample.

    • Local picture Resources

      • If possible, place multiple sizes of picture resources for different scenarios
      • Generate a picture resource for the scenario size for the scenario, and the image generated in the scene
Applicable scenarios

All scenes that need to use the picture can be optimized with this scenario, with no side effects.

Summarize

Sliding performance Optimization This piece of knowledge is very much involved, do not blindly, premature optimization. Use instrument to find bottlenecks and then use different scenarios appropriately. Performance optimization has a lot of kinky tricks, but usually does a few big points above, and basically the performance is acceptable.

For TableView & Collection View This is a very effective optimization method, in the fast sliding, ignoring the middle of the fast flash cell, Directly borrow Uiscrollview's delegate to load the contents of the cell to stop the target area. The practice proves that this method effect is still very obvious, the concrete example can search on the net.

Profile--Optimization, profile

Repeat the process above until you reach your expectations.

The last important thing to say three times:
profile must use the real machine, it is best to use the release mode, in order to achieve the most realistic effect.    profile must use the real machine, it is best to use the release mode, in order to achieve the most realistic effect. profile must use the real machine, it is best to use the release mode, in order to achieve the most realistic effect. More resources:
    • IOS Core animation:advanced Techniques
    • Uiimageview Class Reference
    • Image resizing techniques
    • IOS tips for maintaining smooth interface
    • Alpha compositing

Note:smileevday reserves all rights to this article

  Reprint please the source of the famous source

  All the content in this article represents a personal point of view, if there is something wrong, please point out.

IOS Slide Performance optimization

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.