Горизонтальные секции в UICollectioView 😤


#1

Ребята подскажите, у кого какой интересный опыт реализации был. Вопрос следующий. Сделал программно UICollectionView

  • В одной горизотальной секции видео
  • В второй фото

Вопрос: Как правильно отцентровать секцию, если данные есть только в одной из них?

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)
}