Водопад Коллекция View Swift

Мне нужна помощь по просмотру коллекции водопадов и разделу колонки объявлений.

Я загружаю пример изображения.

Идея такова: представление коллекции должно быть макетом водопада, реклама должна отображаться в одном столбце, а другие - в двух столбцах.

Это интерфейс:

Я не мог исправить это пустое пространствоЯ не мог исправить это пустое пространство

И это мой код:

override func numberOfSections(in collectionView: UICollectionView) -> Int {
    return self.items.count
}

override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    if InterstitialManager.shared.startInterstitialHandled {
        checkIfItemsAvailable()
        return self.items.count
    } else {
        return 0
    }
}

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let cell = self.collectionView!.mp_dequeueReusableCell(withReuseIdentifier: "MainItemCell", for: indexPath) as! MainCollectionViewCell
    cell.item = items[indexPath.row]
    return cell
}

}

override func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
    DispatchQueue.global(qos: .default).async {
        let reloadAfterPercent = 70
        let currentPercent = (indexPath.row * 100) / self.items.count

        if currentPercent > reloadAfterPercent {
            if !self.isRefreshing {
                self.itemStartIndex += AppConstants.collectionViewStartItemsCount
                self.getItemsFromServer(true)
            }
        }
    }
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
    return 5
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
    return 5
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

    if InterstitialManager.shared.startInterstitialHandled {
        checkIfItemsAvailable()

        let item = self.items[indexPath.row]
        let contentSizeWidth = UIScreen.main.bounds.size.width
        let cellWidth = contentSizeWidth / 2.0
        let height = calculateImageHeightFromThumbnail(imageWidth: CGFloat(item.thumbWidth!),
                                                       imageHeight: CGFloat(item.thumbHeight!),
                                                       newWidth: cellWidth)
        let padding: CGFloat =  28
        let collectionViewSize = collectionView.frame.size.width - padding

        self.collectionView?.contentInset = UIEdgeInsets(top: 6, left: 6, bottom: 6, right: 6 )

        return CGSize(width: collectionViewSize/2, height: height + 30)
    } else {
        return CGSize(width: UIScreen.main.bounds.size.width,
                      height: UIScreen.main.bounds.size.height)
    }
}

0 ответов

Другие вопросы по тегам