2017-07-06 1 views
2

ここでは/このセルレイアウトの動作をどのようにコードしますか。カスタムのuicollectionviewレイアウトのコーディング

前のセルと重なるように各セルが必要です。

セル2 centerXは、私は私のカスタムUICollectionViewLayoutにどのようなメソッドをオーバーライドしますセル1の右エッジであるなど...

enter image description here

+0

私はあなたがこれを見ていると思います: https://stackoverflow.com/questions/36393692/uicollectionview - オーバーラップするセルとカスタムの挿入と削除のアニメーション –

答えて

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 
} 
関連する問題