Summary of IOS drawing performance issues raised by drawing shadows

Source: Internet
Author: User

Go from: http://blog.devdlh.com/blog/2013/03/18/performance-problerm-caused-by-shadowpath/drawing Shadow raised IOS drawing performance Issues Summary

MAR 18TH, 2013 | COMMENTS

In IOS development, you can easily add a shadow effect to UIView by setting the Shadowcolor, Shadowopacity, Shadowoffset, and Shadowradius properties of the layer. However, the previous time encountered a problem, after adding a shadow, there will be animation lag phenomenon. After Google found a solution, you need to specify a path for the shadow, that is, set the Shadowpath property of the layer. For example:

1
view.layer.shadowPath = [UIBezierPath  bezierPathWithRect:view.bounds].CGPath;

Drawing shadows creates a lot of offscreen-rendered when you do not specify a shadow path. Offscreen-rendered (off-screen rendering) and Blending (blending) are two of the most performance-impacting aspects of IOS drawings.

Offscreen-rendered

Off-screen rendering means that an area is rendered two times per frame. Most off-screen rendering is caused by shading and masking. With shading as an example, IOS draws the target's shadow first and then draws the target itself. When we do not have a path to the shadow, IOS will recursively calculate the exact path of the shadow before each drawing, which is very performance-intensive and also causes the animation to appear in the same way.

Therefore, you typically need to specify the path to the shadow. When the bound of the View changes, the shadow path is reset. If the bound of the View is animated, you need to animate the Shadowpath using Caanimation.

Reference documentation.

Blending

When you render each frame, IOS calculates the color of each pixel point. When the topmost layer is opaque, simply take the color of the topmost layer. When the upper layer has transparency, it is necessary to mix the colors of each layer to calculate the color of the final display. The more layers that are transparent from top to bottom, the greater the amount of computation, which can also cause performance degradation during animation. Therefore, in the development, we should try to reduce the unnecessary transparent layer.

Using Instruments to detect drawing performance

Using the Instruments Core Animation template makes it easy to detect Blending and offscreen-rendered in your application.

Tick the Color offscreen-rendered Yellow option to highlight areas of off-screen rendering.

Ticking the color blended Layers will show the area where the layer is blended, the darker the colors, the greater the calculation.

Drawing shadow-raised IOS drawing performance issues Summary

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.