首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >定制uicollectionview布局编码

定制uicollectionview布局编码
EN

Stack Overflow用户
提问于 2017-07-06 19:40:54
回答 1查看 206关注 0票数 3

在何处/如何为此单元格布局行为编写代码。

我需要每个细胞重叠以前的。

细胞2 centerX是细胞1的右边缘,等等.

在我的自定义UICollectionViewLayout中,我要重写什么方法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-09 05:04:57

创建自定义collectionView布局时,重写layoutAttributesForItem以配置单元格布局行为.

代码语言:javascript
复制
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
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44957559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档