2017-07-06 70 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 
}