【发布时间】:2019-11-06 23:50:52
【问题描述】:
我正在开发一个 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 添加堆栈卡效果。
请帮帮我。
【问题讨论】:
-
您能分享一下您正在使用的 pod 吗?吊舱本身必须有一个选项以使其适合设备宽度。 @Hilaj
-
pod 'CardsLayout'
-
请考虑删除两个相同的问题之一,谢谢stackoverflow.com/questions/56749188/…
标签: ios swift uicollectionview uicollectionviewflowlayout