When should I set layer.shouldRasterize to YES

后端 未结 1 1247
自闭症患者
自闭症患者 2021-01-29 22:12

I\'ve seen fixes for some lagyness issues by setting the layer property of the view

view.layer.shouldRasterize = YES;

I saw a great difference

相关标签:
1条回答
  • 2021-01-29 22:23

    In WWDC 2012 Polishing Your Interface Rotations video (sadly, no longer available online) they talked about the advantages and implications of rasterizing layers.

    Bottom line if you have a complex view (i.e. relatively expensive to re-render) that you are animating, but for which the animated view is not itself changing, rasterizing the layer can improve the performance by not re-rendering the layer all the time. But it does this at the cost of memory (saving a rasterized image in memory).

    But, if you animate a change within the layer, the shouldRasterize can adversely affect performance (because it's going to re-rasterize the layer for each frame of the animation).

    Generally, if animating a complex set of layers that, themselves, are not changing, then you can set shouldRasterize to YES, do the animation, and then turn off shouldRasterize.

    0 讨论(0)
提交回复
热议问题