简体   繁体   中英

Improving performance of Core Animation

I have built a UI where the majority of what's on screen is put there using CALayer's. The layers are fairly simple in terms of their setup; the majority have an image set as their contents and a couple have a shadow. There are also some CALayer derivatives such as CATextLayer and CAGradientLayer . At any one time there is about 18 layers on screen. The contents of 11 layers change frequently ( but not to represent an animation ), and the same 11 can be scrolled to the left or the right as they are embedded in a UIScrollView .

I have noticed that performance is a little sluggish on both my 3GS and 4 so I am looking for ways to tune what I have to hopefully improve performance somewhat.

I have set rasterizationScale to the appropriate scale depending on the device and have set shouldRasterize to YES .

The images are passed to the layers in the following way ...

someLayer.contents = (id)someUIImage.CGImage

Is there anything else I can do to improved the overall performance?

The best thing to do would be to use the profiling tools available to you to figure out exactly what is slowing you down.

This previous answer says it better than I could: iOS / Core-Animation: Performance tuning

您可以使用CATiledLayer而不是CALayer,这将在单独的线程中渲染图像,并且肯定会提高性能。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM