我有一个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
属性有缺点。当我向下滚动时,它会花费一些时间来加载位图。有没有办法预先渲染这些细胞?没有重用标识符的表是否可以解决问题?
我绝对需要阴影,但我不会为他们牺牲性能。我希望有人可以提供帮助。