[IOS Animation]-calayer Drawing efficiency-asynchronous drawing

Source: Internet
Author: User

Drawing asynchronously

Uikit's single-threaded nature means that boarding maps are updated on the main thread, which means that drawing interrupts user interaction and even makes the entire app appear unresponsive. There's nothing we can do about it, but it's much better to avoid the user waiting for the drawing to finish.

There are some ways to do this: in some cases, we can presumably draw the content on another thread ahead of time, and then set the resulting picture directly to the content of the layer. This may not be convenient to implement, but it is feasible in certain situations. Core Animation offers some options: CATiledLayer and drawsasynchronously properties.

Catiledlayer

We explored it briefly in the sixth chapter CATiledLayer . In addition to splitting the layer again into a small, independent update (similar to the concept of automatic updating of dirty rectangles), CATiledLayer There is an interesting feature: calling a method on multiple threads for each small block at the same time -drawLayer:inContext: . This avoids blocking user interaction and being able to draw faster with multi-core new slices. Only one small piece CATiledLayer is an easy way to implement an asynchronous update of a picture view.

drawsasynchronously

ios 6, Apple introduced this curious property for Calayer , drawsasynchronously property for incoming  -drawlayer:incontext:   cgcontext changes to allow cgcontext to delay the execution of the drawing command so that user interaction is not blocked.

Catiledlayer . Its own  -drawlayer:incontext: The   method is only called on the main thread, but Cgcontext does not wait for the end of each drawing command. Instead, it joins the command into the queue and, when the method returns, performs a real drawing on a per-background thread.

According to Apple's statement. This feature works best on views that require frequent redrawing (such as our drawing app, or something like that UITableViewCell ), and is not much help for layers that are drawn only once or rarely redrawn.

Summarize

In this chapter we discuss some of the performance challenges with the core graphics software drawing, and then explore some improvements: such as improving drawing performance or reducing the amount of paint that needs to be drawn.


[IOS Animation]-calayer Drawing efficiency-asynchronous drawing

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.