【问题标题】:UICollectionViewCell shadow causes small lagUICollectionViewCell 阴影导致小滞后
【发布时间】:2015-12-21 22:54:33
【问题描述】:

在我的 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

有什么建议吗?

【问题讨论】:

  • 您是在 Interface Builder 中创建了一个标识符为 imageCell 的单元格,还是全部在代码中完成?
  • @Jay 单元格是在 Interface Builder 中创建的,是的。
  • 您找到解决方案了吗?我遇到了类似的问题
  • @JayVDiyk 我删除了阴影。没有阴影看起来也更专业。

标签: ios swift uicollectionview


【解决方案1】:

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

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

Apple mentions

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

【讨论】:

    【解决方案2】:

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

    但真正发挥作用的是光栅化

    cell.layer.shouldRasterize

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-03
      • 1970-01-01
      • 2016-08-22
      相关资源
      最近更新 更多