移动时禁用 CALayer 内容的重绘 (iphone)

发布于 2024-08-03 22:49:23 字数 293 浏览 2 评论 0原文

我有一个带有大量 CALayers(~1000)的 UIView,每个 CALayers 都有一个小图像作为其内容。这个 UIView 是滚动视图的子视图(实际上它是另一个视图的子视图,而另一个视图是滚动视图的子视图)。一开始绘制速度相对较快(几秒钟)。但是,当我在滚动视图中滚动时,帧速率非常低。

每次滚动时它是否都会尝试重新绘制每个 CALayer 的内容?有办法禁用这个吗?是不是还有什么事情发生?

注意:我将 UIView 中的clearsContextBeforeDrawing 设置为 NOo,这有所帮助,但仍然比我预期的慢得多

I have a UIView with a large number of CALayers (~1000), each of which has a small image as its contents. This UIView is a subview of a scrollview (actually it's a subview of another view which is a subview of the scrollview). This draws relatively quickly at first (couple seconds). However when I scroll in the scrollview the frame rate is very low.

Is it trying to redraw the contents of each CALayer every time I scroll? Is there a way to disable this? Is something else going on?

Note: I set clearsContextBeforeDrawing to NOo n my UIView and this helped somewhat but it's still much slow than I would expect

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自由范儿 2024-08-10 22:49:23

不应重新绘制图层,但它们将使用 GPU 进行合成。尝试使用 Instruments 中的 Sampler 和 OpenGL ES 仪器来查看瓶颈是否在 CPU 或 GPU 中。您可以通过点击仪器名称旁边的“i”并选择额外参数(平铺器利用率、渲染器利用率等)来记录 OpenGL ES 仪器中的额外详细信息。如果其中一个 OpenGL 值接近 100%,那么就是合成阻碍了您。但是,如果采样器显示对 -drawRect: 或类似方法的多次调用,则您的图层将被重绘(出于某种原因),这可能是问题所在。

此外,您可以使用核心动画工具为非不透明图层着色,这会降低显示帧速率。

The layers should not be redrawn, but they will be composited using the GPU. Try using the Sampler and OpenGL ES instruments in Instruments to see if your bottleneck is in the CPU or GPU. You can log extra detail within the OpenGL ES instrument by tapping on the "i" next to the instrument name and selecting the extra parameters (Tiler Utilization, Renderer Utilization, etc.). If one of the OpenGL values is near 100%, then it's the compositing that's holding you back. However, if the sampler is showing a number of calls to -drawRect: or similar methods, then your layers are being redrawn (for some reason) and that could be the problem.

Additionally, you can use the Core Animation instrument to color non-opaque layers, which can lower your display framerate.

复古式 2024-08-10 22:49:23

将图层上的 needsDisplayOnBoundsChange 属性设置为 NO

[layer setNeedsDisplayOnBoundsChange:NO];

Set the needsDisplayOnBoundsChange property on your layers to NO:

[layer setNeedsDisplayOnBoundsChange:NO];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文