ios - UICollectionViewCell 阴影导致小延迟

标签 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

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

最佳答案

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

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

Apple mentions

Specifying an explicit path usually improves rendering performance.

关于ios - UICollectionViewCell 阴影导致小延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34405740/

相关文章:

swift - 我应该在 Swift 中使用解构的 CollectionView 还是多图像?

ios - 有没有办法禁用 'iOS Team Provisioning Profile: *' 自动创建?

Javascript延迟关闭IOS上的数字键盘

ios - 安装失败: Invalid Argument - System Error

ios - 获取前往位置的步行路线

ios - 表格 View 中的嵌套 Collection View 更好或多个 Collection View

ios - 如何在 Swift/iOS 中将静态 TableView Controller 单元格限制到安全区域

ios - 无法使用 JSON 类型的参数列表调用类型 'Int' 的初始值设定项

ios - GameplayKit 寻路使用什么算法?

ios - 如何在 UICollectionView 上方添加搜索栏?