我有一个集合视图,当我在更大屏幕上运行应用程序时,单元格的高度不会改变iPhone我使用此代码但是当我运行此代码时,我无法在我的应用程序中看到我的集合视图
请记住我的水平收藏视图包含一行
var cellWidth:CGFloat = 0
var cellHeight:CGFloat = 0
var spacing:CGFloat = 12
var numberOfColumn:CGFloat = 9
//Scale Collection View
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
specialCollectionView.contentInset = UIEdgeInsets(top: spacing, left: spacing, bottom: spacing, right: spacing)
if let flowLayout = specialCollectionView.collectionViewLayout as? UICollectionViewFlowLayout{
cellHeight = view.frame.size.height / specialCollectionView.frame.height
flowLayout.minimumLineSpacing = spacing
flowLayout.minimumInteritemSpacing = spacing
}
}
这是扩展代码
extension secondTabViewController:UICollectionViewDelegateFlowLayout{
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: cellWidth, height: cellHeight)
}
}