0

我有多个部分和垂直滚动的collectionview。每个人只有一项。

画面流程如下:

  • 我调用一个 api,它为我提供 feedId 和 url 以获取部分数据。

  • 当用户滚动时,collectionview api 被调用以获取当前在屏幕上可见的部分。

  • 在每个 collectionview 单元格(或部分)内都有另一个带有网格布局的 collectionview,它呈现如下的网格图像

在此处输入图像描述

外部收藏视图

我正在使用具有组合布局的 Diffable 数据源,并且在应用快照时,代码如下所示。

if #available(iOS 15.0, *) {
     updateSnapshot.reconfigureItems([item])
} else {
     updateSnapshot.reloadItems([item])
                // Fallback on earlier versions
}

if #available(iOS 15.0, *) {
    dataSource.applySnapshotUsingReloadData(updateSnapshot)
} else {
  dataSource.apply(updateSnapshot, animatingDifferences: false, completion: nil)
                // Fallback on earlier versions
}

内部collectionview代码如下

var dataSource = RxCollectionViewSectionedReloadDataSource<SectionModel<String, GlobalGalleryViewModel>> {[] (ds, cv, indexPath, vm) -> UICollectionViewCell in
    let cell = cv.dequeueReusableCell(withReuseIdentifier: GlobalGalleryCell.className, for: indexPath) as! GlobalGalleryCell
    cell.configureCell(vm)
    return cell
}

问题

当我滚动外部集合视图时,当内部画廊在外部集合视图单元格上呈现时,会出现很多故障和闪烁。

Outer collectionview的布局代码

  let parentItemSize = NSCollectionLayoutSize(
          widthDimension: .fractionalWidth(1.0),
          heightDimension:feedInterface.isHaveActualFeed ? .estimated(height) : .fractionalHeight(1)
        )
  let largeItem = NSCollectionLayoutItem(layoutSize: parentItemSize)         
  largeItem.contentInsets = NSDirectionalEdgeInsets(top: parentInset, leading: parentInset, bottom: parentInset, trailing: parentInset)
        
        // Outer Group
  let outerGroupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension:.estimated(height))
  let outerGroup = NSCollectionLayoutGroup.vertical(layoutSize: outerGroupSize, subitems: [largeItem])
        

还像这样添加了单元格预取

func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) {
    self.updateVisibleCellRemotely(indexPaths)
    
    if let lastIndexPath = indexPaths.last,
       lastIndexPath.section == (self.feeds.count - 1),
       self.feeds.count > 0 {
        self.viewModel.fetchBottomFeedData()
    }///load more vertical or main feed or parent feed
}

任何解决方案将不胜感激。

4

0 回答 0