Быстрое горизонтальное представление коллекции с динамической высотой ячейки - PullRequest
0 голосов
/ 11 октября 2019

У меня есть два горизонтальных вида коллекции внутри вертикального прокрутки. Верхний вид коллекции имеет фиксированную высоту 300 ячеек, но нижний вид коллекции должен иметь динамическую высоту, основанную на размере содержимого. Я сделал это:

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    if collectionView == headerCollectionView {
        return CGSize(width: view.bounds.width, height: 300)
    }
    if collectionView == contentCollectionView {
        return CGSize(width: view.bounds.width, height: contentHeight.constant)
    }
    return CGSize(width: 0, height: 0)
}

Затем в моем методе cellForItemAt я пытаюсь изменить ограничение contentHeight, но после этого мой контент движется вниз, даже если я установил свой contentTopConstraint равным 0.

Что я могу сделать здесь?

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    if collectionView == contentCollectionView {
        let contentCell = collectionView.dequeueReusableCell(withReuseIdentifier: "ContentCell", for: indexPath) as! ContentCell
        contentCell.setNames(currentBlock.items[indexPath.row])
        if contentCell.name.countLabelLines() > 1 {
           self.contentHeight.constant += 34
        }[![enter image description here][1]][1]
        APIManager.load(item_id: currentBlock.items[indexPath.row].id) { (apiItem, error) in
            if error == nil {
                DispatchQueue.main.async {
                   contentCell.setContent(apiItem!)
                }
            }
        }
        return contentCell
    }
    return UICollectionViewCell()
}

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...