我在哪里/如何编码此单元格布局行为。
我需要每个单元格与之前的单元格重叠。
Cell 2 centerX是Cell 1右边缘等等......
我会在自定义UICollectionViewLayout中覆盖哪种方法?
答案 0 :(得分:2)
创建自定义collectionView布局时,覆盖layoutAttributesForItem
以配置单元格布局行为...
var preferredSize: CGSize? = CGSize(width: 100, height: 100)
override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)
attributes.size = preferredSize!
//Modifying the centerX property adjust the overlapping effect
let centerX = (preferredSize?.width)! / 2.0 + CGFloat(indexPath.item) * ((preferredSize?.width)! * 0.5 )
let centerY = collectionView!.bounds.height / 2.0
attributes.center = CGPoint(x: centerX, y: centerY)
attributes.zIndex = -(indexPath.item)
return attributes
}