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

查看:14
本文介绍了在单元格上设置角半径会破坏 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天全站免登陆