2017-07-06 74 views
2

Where /我将如何编码此单元布局行为。编码自定义uicollectionview布局

我需要每个单元格重叠以前。

小区2的centerX是小区1个右边缘等等...

enter image description here

我会重写我的自定义UICollectionViewLayout用什么方法?

+0

我猜你正在寻找这样的: https://stackoverflow.com/questions/36393692/uicollectionview -with重叠细胞和 - 定制插入和缺失-阿尼马特 –

回答

0

创建自定义的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 
}