问题描述
通过设置视图的layer属性,我已经看到了一些延迟问题的解决方法
I've seen fixes for some lagyness issues by setting the layer property of the view
view.layer.shouldRasterize = YES;
使用UICollectionView并准备单元格并设置属性时,我看到了性能上的巨大差异.
I saw a great difference in performance when using a UICollectionView and preparing the cells and setting the propery.
不确定会带来什么影响.
Not sure what the implications are.
很高兴获得解释.谢谢!
Would be great to get an explanation.Thanks!
推荐答案
在WWDC 2012中,抛光界面旋转"视频(不幸的是,不再在线提供)中,他们谈到了栅格化图层的优点和含义.
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).
但是,如果为图层中的变化设置动画,则shouldRasterize
会对性能产生不利影响(因为它将为动画的每一帧重新栅格化图层).
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).
通常,如果要对一组本身不变的复杂图层进行动画处理,则可以将shouldRasterize
设置为YES
,进行动画处理,然后关闭shouldRasterize
.
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
.
这篇关于什么时候应该将layer.shouldRasterize设置为YES的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!