UICollectionViewCell阴影导致小滞后

时间:2015-12-21 22:54:33

标签: ios swift uicollectionview

在我的UICollectionView中向下滚动时,它会滞后,并由此引起:

imageCell?.backgroundColor = UIColor.whiteColor()
imageCell?.layer.masksToBounds = false
imageCell?.layer.shadowOpacity = 0.5
imageCell?.layer.shadowRadius = 5.0
imageCell?.layer.shadowOffset = CGSizeZero
imageCell?.layer.shadowColor = UIColor.grayColor().CGColor

imageCell是单元名称:

let imageCell = collectionView.dequeueReusableCellWithReuseIdentifier("imageCell", forIndexPath: indexPath) as? CollectionViewCell

有什么建议我应该做什么?

2 个答案:

答案 0 :(得分:1)

使用阴影时,如果您知道形状,最好指定shadowPath

imageCell?.layer.shadowPath = UIBezierPath(rect: imageCell?.frame ?? CGRectZero).CGPath

Apple mentions

  

指定显式路径通常可以提高渲染性能。

答案 1 :(得分:0)

当我使用太大的图像时,我遇到了同样的事情。然后我转换为.png并使它们变小 - 这有帮助。 (不确定您是否使用任何图像)。

但真正有所作为的是光栅化

cell.layer.shouldRasterize