【发布时间】:2017-01-17 09:17:31
【问题描述】:
我正在尝试在我的应用中实现 Pinterest 布局
我使用以下委托方法来实现并动态设置单元格高度
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let boundingRect = CGRect(x: 0, y: 0, width: self.view.frame.size.width / 2 - 20, height: CGFloat(MAXFLOAT))
let data = articles[indexPath.row]
let rect = AVMakeRect(aspectRatio: (data.coverImage?.size)!, insideRect: boundingRect)
return CGSize(width: rect.width, height: rect.height + 120) // Added 120 for a description I will add later
}
但我得到了以下结果:
灰色背景是单元格的背景,可以看到每个单元格都有自己的高度(如预期的那样) 但是有额外的空白我不知道如何删除。
我该如何解决这个问题?
【问题讨论】:
-
没有人试过这个?为什么没有答案?
-
你找到解决办法了吗?
标签: swift uicollectionviewcell pinterest