CALayer优化? [英] CALayer optimizations?

查看:146
本文介绍了CALayer优化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在添加几个CALayers作为UIView层的子层。每层的内容是从服务器下载的不同图像。每个图层从屏幕外动画到随机生成的位置。图像数据是异步下载的。每张图片大约为300x300或更小。

I'm adding several CALayers as sublayers of the layer of a UIView. The contents of each layer is a different image downloaded from a server. Each layer is animated from offscreen to a randomly generated position. The image data is downloaded asynchronously. Each image is approx 300x300 or smaller.

由于随机放置,图层重叠,有些图层被其上方的图层遮挡。这一切都很好。

As a result of the random placement, the layers overlap and some are obscured by the layers above them. This is all good.

我正在使用这个问题的答案确定覆盖范围的计算发生在一个单独的线程上。

I'm removing layers as they become completely obscured from view using the suggestion in the answer to this question The calculations to determine coverage occur on a separate thread.

我有一个UIPanGestureRecognizer,允许用户在屏幕上拖动图层。

I have a UIPanGestureRecognizer that allows the user to drag the layers around on the screen.

我是当添加的层数接近25-30并且逐渐变差时遇到性能问题。动画变得不稳定并且通常完全不存在(新添加的层只是出现在它们的最终位置)。并且平移手势要么被忽略,要么导致所选图层的重新定位不稳定。

I'm encountering a performance problem when the number of layers added approaches 25-30 and gets progressively worse. The animations become choppy and often are completely absent (the newly added layers simply appear in their final position). And the pan gestures are either ignored or result in choppy repositioning of the selected layer.

我假设我正在杀死所有层重叠的GPU并且另一层动画上面?

I'm supposing that I'm killing the GPU with all of the layers overlapping and another layer animating above?

有关如何提高绩效的任何建议?

Any suggestions on how to improve performance?

处理大量图层的最佳做法?

Best practices for dealing with large numbers of layers?

让图层开始动画更好吗?一个单独的view.layer比以前添加的图层?

Is it better to have the layer begin animated in a separate view.layer than the previously added layers?

谢谢!

推荐答案

快速检查几件事。

运行Core Animation Instrument并查找不透明度。仅将图层的不透明标志设置为YES是不够的,如果底层图像具有alpha组件,则图层将考虑该值。

Run the Core Animation Instrument and look for opacity. Just setting the layer's opaque flag to YES is not enough, if the underlying image has an alpha component the layer will take that into consideration.

如果您从中获取数据你的服务器有alpha,然后你应该用Quartz重绘并以不包含alpha的新格式在本地保存文件。

If the data you are getting from your sever has alpha then you should redraw with Quartz and save the file locally in the new format that does not include alpha.

确保你没有放入1兆像素图像分为100x100个瓷砖。同样是Core Animation Instrument,打开'Color Misaligned Images'并寻找黄色。

Make doubly sure that you are not putting 1 mega pixel images into 100x100 tiles. Also Core Animation Instrument, switching on 'Color Misaligned Images' and look for yellow.

30到50层应该没问题。

30 to 50 layers should be no problem.

这篇关于CALayer优化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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