gpt4 book ai didi

swift - SizeForItemAtIndexPath : get items standard size

转载 作者:行者123 更新时间:2023-11-28 10:50:49 28 4
gpt4 key购买 nike

我在具有两个 Collection View 的 View Controller 中使用 sizeForItemAtIndexPath 函数。

如何在 sizeForItemAtIndexPath 函数中排除一个 Collection View ,或者如何在不更改任何内容的情况下获得原始单元格大小?

最佳答案

  • 排除一个 Collection View

     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    // to exclude one collection view
    if collectionView == collectionViewOne {}// first
    if collectionView.tag == number(you set before){}// second

    // to get the original cell size without changing anything
    //let yourSize = collectionViewLayout.itemSize
    //return collectionViewLayout.itemSize // if you have set it globally,
    /*
    But you can not get it, because itemSize is a property of UICollectionViewFlowLayout.

    And you can't cast collectionViewLayout to UICollectionViewFlowLayout Class which is kind of UICollectionViewLayout Class .

    Thats not how inheritance works.
    */
    }
  • 在不改变任何东西的情况下获得原始单元格大小

    let indexPath = IndexPath(item: number(you choose), section: number(you choose, 0 or 1))
    let layout = UICollectionViewFlowLayout() // you set
    // got the size
    // more generally, if you have set layout per item through delegate.
    let size = self.collectionView(collectionViewOne, layout: layout, sizeForItemAtIndexPath: indexPath)
    // or try this ,if you have configured globally
    let itemSize = layout.itemSize

关于swift - SizeForItemAtIndexPath : get items standard size,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46265744/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com