【问题标题】:Custom UICollectionViewLayout and constraints自定义 UICollectionViewLayout 和约束
【发布时间】:2016-09-16 15:52:06
【问题描述】:

我有一个自定义流程布局。我知道我的细胞需要放在哪里。我目前为每个单元格创建特定的框架。但是,我担心不同尺寸的 iPhone,所以我想探索创建约束。我知道这必须在函数中完成 准备布局()。

override func prepareLayout() {
    for item in 0 ..< collectionView!.numberOfItemsInSection(0){
        let indexPath = NSIndexPath(forItem: item, inSection: 0)
        let attributes = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath)
        cache.append(attributes)
    }
    //This is where I want to do work for creating constraints for my cells
}

我想问题是你可以在创建自己的自定义流布局时在单元格之间创建约束

【问题讨论】:

    标签: ios swift uicollectionview uicollectionviewlayout


    【解决方案1】:

    问题是您可以在创建自己的自定义流布局时在单元格之间创建约束

    没有。约束和集合视图布局是相反的。集合视图布局按帧定位项目。

    但是,您知道集合视图尺寸是什么 (self.collectionView!.bounds.size),因此您的项目框架可以考虑到这一点。他们应该这样做!毕竟,这就是正常流布局的工作方式,当它隔开一行以使其左右对齐时。这只是做一些基本算术的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-13
      • 2016-11-23
      • 1970-01-01
      • 1970-01-01
      • 2018-06-17
      • 2016-12-05
      • 2017-04-25
      • 2019-11-02
      相关资源
      最近更新 更多