繁体   English   中英

编码自定义uicollectionview布局

[英]coding for custom uicollectionview layout

我将如何/如何编码此单元格布局行为。

我需要每个单元格与之前的单元格重叠。

Cell 2 centerX是Cell 1右边缘等等......

在此输入图像描述

我将在自定义UICollectionViewLayout中覆盖哪种方法?

创建自定义collectionView布局时,覆盖layoutAttributesForItem以配置单元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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM