1

我有一个UITableView包含图层阴影的单元格,它们的子视图也有。总而言之,每个单元格大约有 5 个阴影。我重用了我的单元格,但是当内容超过某个高度时它们偶尔会改变它们的高度(我这么说是因为这可能会导致更多的绘制调用以及我在下面列出的“优化”)。

现在,我添加了以下优化:

// setting it opaque will tell the GPU not to blend the 
// layer (-> less draw calls - only useful when layer completely opaque obviously)
myShadowView.opaque = YES;

// another significant factor was the shadowPath property, 
// it significantly smoothed scrolling
myShadowView.layer.shadowOffset = CGSizeMake(0, -1);
myShadowView.layer.shadowOpacity = 0.08;
myShadowView.layer.shadowRadius = 1;
myShadowView.layer.shadowPath = [UIBezierPath bezierPathWithRect:shad.bounds].CGPath;

// the most important change
myShadowView.layer.shouldRasterize = YES;
myShadowView.layer.rasterizationScale = [UIScreen mainScreen].scale;

我对性能非常满意——滚动就像婴儿皮肤一样光滑——但该shouldRasterize属性也有缺点。当我向下滚动时,单元格需要一点时间来加载位图。有没有办法预渲染这些单元格?没有重用标识符的表会解决这个问题吗?

我绝对需要阴影,但我不会为它们牺牲性能。我希望有人能提供帮助。

4

0 回答 0