我的视图控制器中有2个集合视图,我只想为其中一个设置collectionView sizeForItemAt
方法,而不更改另一个视图。
我必须为他们两个都设置其他代表。
func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAt indexPath: IndexPath) -> CGSize {
if (collectionView == collectionView1) {
return CGSize(width: 158,height: 90)
} else if (collectionView == collectionView2) {
let collectionWidth = (collectionView.bounds.size.width - 20) / 3
return CGSize(width: collectionWidth,height: collectionWidth)
}
}
我不想为collectionview2
返回任何内容,因为它的大小是动态的,并且取决于设备的大小。这是由flowLayout完成的。
有没有一种方法可以为第一个方法实现?