在单元格上设置角半径会导致UICollectionView的性能下降 [英] Setting corner radius on a cell kills UICollectionView's performance

查看:89
本文介绍了在单元格上设置角半径会导致UICollectionView的性能下降的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个只有几个单元格(约20个)的 UICollectionView 。这个系列的性能非常好。但是,只要我尝试围绕此视图呈现的 UICollectionViewCells 的角落,我的性能就会受到重创。在我的单元格的init方法中,这是我添加的唯一一行导致这个:

I have a UICollectionView that has only a few cells (about 20). Performance for this collection works great. However, as soon as I try to round the corners of the UICollectionViewCells that are being rendered by this view, my performance takes a significant hit. In my cell's init method, this is the only line I add to cause this:

[self.layer setCornerRadius:15];

由于这是在init方法中我正在重复使用单元格,我不明白为什么这应该是我的问题。

Since this is in the init method and I am reusing the cells properly, I don't see why this should be causing me issue.

我尝试使用以下多种组合来调整卖出的光栅化和不透明度,但仍无效果:

I have tried adjusting the rasterization and opacity of the sell using multiple combinations of the following, with still no effect:

[self.layer setMasksToBounds:YES];
[self.layer setCornerRadius:15];
[self.layer setRasterizationScale:[[UIScreen mainScreen] scale]];
self.layer.shouldRasterize = YES;
self.layer.opaque = YES;

他们的一些设置或技巧可以提高 UICollectionView的性能有圆角的单元格?

Is their some setting or trick to improve the performance of a UICollectionView that has cells with rounded corners?

推荐答案

正如@Till在评论中指出的那样,预呈现的图像应该可以解决你的问题性能问题。您可以将所有角落舍入,阴影和任何其他特殊效果放入其中,而不需要CA即时渲染它们。

As @Till noted in comments, a prerendered image should solve your performance problem. You can put all the corner rounding, shadowing, and whatever other special effects into that instead of needing CA to render them on the fly.

预渲染图像不会锁定您进入静态内容大小,或者:查看 UIImage 可调整大小的图像。 (这仍然比每帧渲染CA的速度快。)

Prerendered images don't lock you into a static content size, either: look into the UIImage resizable image stuff. (That's still way faster than CA rendering every frame.)

这篇关于在单元格上设置角半径会导致UICollectionView的性能下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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