提高核心动画的性能
我构建了一个 UI,屏幕上的大部分内容都是使用 CALayer 放置在那里的。这些层的设置相当简单;大多数都有图像作为其内容,少数有阴影。还有一些 CALayer
衍生产品,例如 CATextLayer
和 CAGradientLayer
。任何时候屏幕上大约有 18 层。 11层的内容经常变化(但不代表动画),并且相同的11层可以向左或向右滚动,因为它们嵌入在UIScrollView
中。
我注意到我的 3GS 和 4 的性能都有点迟缓,因此我正在寻找方法来调整我所需要的内容,希望能在一定程度上提高性能。
我已根据设备将 rasterizationScale
设置为适当的比例,并将 shouldRasterize
设置为 YES
。
图像通过以下方式传递到图层...
someLayer.contents = (id)someUIImage.CGImage
我还能做些什么来提高整体性能吗?
I have built a UI where the majority of what's on screen is put there using CALayer's. The layers are fairly simple in terms of their setup; the majority have an image set as their contents and a couple have a shadow. There are also some CALayer
derivatives such as CATextLayer
and CAGradientLayer
. At any one time there is about 18 layers on screen. The contents of 11 layers change frequently (but not to represent an animation), and the same 11 can be scrolled to the left or the right as they are embedded in a UIScrollView
.
I have noticed that performance is a little sluggish on both my 3GS and 4 so I am looking for ways to tune what I have to hopefully improve performance somewhat.
I have set rasterizationScale
to the appropriate scale depending on the device and have set shouldRasterize
to YES
.
The images are passed to the layers in the following way ...
someLayer.contents = (id)someUIImage.CGImage
Is there anything else I can do to improved the overall performance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好的办法是使用可用的分析工具来准确找出是什么拖慢了您的速度。
之前的回答比我能说的更好:
iOS / Core-Animation:性能调整
The best thing to do would be to use the profiling tools available to you to figure out exactly what is slowing you down.
This previous answer says it better than I could:
iOS / Core-Animation: Performance tuning
您可以使用 CATiledLayer 而不是 CALayer,它将在单独的线程中渲染图像,并且肯定会提高您的性能......
You could use a CATiledLayer instead of a CALayer, which will render the images in a separate thread and will definitely improve your performance...