Программно UICollectionView с горизонтальными секциями - PullRequest
0 голосов
/ 01 февраля 2019

Как можно центрировать одну секцию представления коллекции в центре, если одна из двух секций пуста?

Пример

func numberOfSections (в collectionView:UICollectionView) -> Int {return 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)
}
...