我正在开发一个 iOS 项目,Swift。我们如何为一个 collectionView 分配两种不同的流布局?在这里,我需要我的 UICollectionViewCell 看起来像一个堆栈卡,为此,我使用 CardsCollectionViewLayout(外部 pod 文件)。
myCollectionView.collectionViewLayout = CardsCollectionViewLayout()
它工作正常。但问题是我无法使用设备宽度调整 UICollectionViewCell 宽度。为此,我需要使用 UICollectionViewDelegateFlowLayout。
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize {
let nCol = 1
let flowLayout = collectionViewLayout as! UICollectionViewFlowLayout
let totalSpace = flowLayout.sectionInset.left
+ flowLayout.sectionInset.right
+ (flowLayout.minimumInteritemSpacing * CGFloat(nbCol - 1))
let size = Int((collectionView.bounds.width - totalSpace) / CGFloat(nbCol))
return CGSize(width: size, height: 284)
}
但是当我使用 CardsCollectionViewLayout 作为我的 collectionView 布局时,我没有在上面的方法中得到回调。
或者
有什么方法可以用我的 UICollectionViewCell 添加堆栈卡效果。
请帮我。