gpt4 book ai didi

ios - 1 个 UIviewcontroller 中的 2 个 UIcollectionview 具有 2 个不同的 UIcollectionflowlayout?

转载 作者:行者123 更新时间:2023-11-30 11:20:48 25 4
gpt4 key购买 nike

我知道有没有办法在 1 个 UIviewcontroller 中实现 2 个 UIcollectionview 和 2 个不同的 UIcollectionflow 布局。主要问题是一个 UIcollectionview 符合 iOS UIcollectionviewflowlayout ,另一个符合 Waterfalllayout 。因为我现在面临的问题是我不能在一个 UIviewcontroller 中同时拥有这两个委托(delegate)函数。谢谢大家。

 func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

}


func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

}

最佳答案

     //: Playground - noun: a place where people can play

import UIKit

class Controller: UIViewController, UICollectionViewDelegateFlowLayout, WaterfallLayoutDelegate {

let collectionView = UICollectionView(frame: CGRect.zero)
let waterfallCollectionView = UICollectionView(frame: CGRect.zero)

override func viewDidLoad() {

collectionView.delegate = self
collectionView.collectionViewLayout = UICollectionViewFlowLayout()

waterfallCollectionView.delegate = self
let waterfallLayout = WaterfallLayout()
waterfallLayout.delegate = self
waterfallCollectionView.collectionViewLayout = waterfallLayout
}

//MARK: - WaterfallLayoutDelegate

func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

return CGSize.zero
}

//MARK: - UICollectionViewDelegateFlowLayout

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

return CGSize.zero
}
}

//MARK: - Just for test

protocol WaterfallLayoutDelegate: class {

func collectionView(_ collectionView: UICollectionView, layout: WaterfallLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
}

class WaterfallLayout: UICollectionViewLayout {

weak var delegate: WaterfallLayoutDelegate?
}

一切正常。

关于ios - 1 个 UIviewcontroller 中的 2 个 UIcollectionview 具有 2 个不同的 UIcollectionflowlayout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51286616/

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