如果两个部分之一为空,如何将集合视图的一个部分居中居中?
func numberOfSections(在collectionView中:UICollectionView)-> Int { 返回2 }
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.section == 1 {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: previewCellId, for: indexPath) as! previewCollectionViewCell
if previewImageAll.count > 0 {
cell.images = previewImageAll
} else {
print("\nEmpty Images")
}
return cell
}
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: videoCellId, for: indexPath) as! VideoCollectionViewCell
if storiesVideoAll.count > 0 {
cell.video = previewVideoAll
} else {
print("\nEmpty Video")
}
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if #available(iOS 11.0, *) {
return CGSize(width: view.safeAreaLayoutGuide.layoutFrame.width, height: 300)
} else {
return CGSize(width: view.frame.width, height: 300)
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
if section == 1 {
return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}