UIView self.layer.shouldRasterize = YES和性能问题 [英] UIView self.layer.shouldRasterize = YES and performance issues

查看:573
本文介绍了UIView self.layer.shouldRasterize = YES和性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想分享我在UIViews上使用 self.layer.shouldRasterize = YES; 标志的经验。

I would like to share my experience from using self.layer.shouldRasterize = YES; flag on UIViews.

我有 UIView 类层次结构,其中 self.layer.shouldRasterize 已启用 ON 为了提高滚动性能(所有这些都具有大于设备屏幕的STATIC子视图)。

I have a UIView class hierarchy that has self.layer.shouldRasterize turned ON in order to improve scrolling performance (all of them have STATIC subviews that are larger than the screen of the device).

今天在其中一个子类中我使用 CAEmitterLayer 来产生漂亮的粒子效果。

Today in one of the subclasses I used CAEmitterLayer to produce nice particle effects.

表现非常差虽然粒子数确实低(50粒子)

这个问题的原因是什么?

What is the cause of this problem?

推荐答案

我将引用Apple Doc并解释:

I'll just quote Apple Doc and explain:

@property BOOL shouldRasterize




当此属性的值为YES时,图层为
在其本地坐标空间中呈现为位图,然后将
与其他任何其他目标合并到目标内容。滤镜属性中的阴影效果和任何
滤镜都被栅格化并包含在
位图中。但是,图层的当前不透明度未进行栅格化。
如果光栅化位图在合成期间需要缩放,则minificationFilter和magnificationFilter属性
中的
过滤器将根据需要应用。

When the value of this property is YES, the layer is rendered as a bitmap in its local coordinate space and then composited to the destination with any other content. Shadow effects and any filters in the filters property are rasterized and included in the bitmap. However, the current opacity of the layer is not rasterized. If the rasterized bitmap requires scaling during compositing, the filters in the minificationFilter and magnificationFilter properties are applied as needed.

所以基本上当shouldRasterize设置为YES时,将计算构成图层的每个像素,并将整个图层缓存为位图。

So basically when shouldRasterize is set to YES, every pixel that will compose the layer is calculated and the whole layer is cached as a bitmap.


  • 你什么时候可以从中受益?

当你只需要画一次。这意味着当你需要纯粹的简单动画(例如移动,变换,缩放......)时,因为CoreAnimation实际上将使用该层而不是每帧重绘它。这是一个非常强大的功能,可以将复杂的图层(阴影和圆角半径)与CoreAnimation结合使用。

When you only need to draw it once. That means when you need just pure "simple" animation (eg moving, transform, scaling...) because CoreAnimation will actually use that layer without redrawing it every frame. It's a very powerful feature to cache complex layers (with shadows and corner radius) combined with CoreAnimation.


  • 什么时候会杀死你的帧速率?

当您的图层重新显示多次时,因为在图纸的顶部已经生效, shouldRasterize 将处理所有像素以缓存位图数据。

When your layer is redisplayed many times, because on top of the drawing that is already taking effect, the shouldRasterize will process all pixels to cache the bitmap data.

因此,您应该问自己的真正问题是: 我在哪个层上应用 shouldRasterize 为YES?这个图层重绘的频率是多少?

So the real question you should ask yourself is this : "On which layer am I applying the shouldRasterize to YES ? And how often is this layer redrawn ?"

希望这很清楚。

这篇关于UIView self.layer.shouldRasterize = YES和性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆