遇到类似问题,这样解决
// swiftlint:disable line_length type_name
final class RxCollectionViewSectionedReloadDataSourceAndDelegate<Section: SectionModelType>: RxCollectionViewSectionedReloadDataSource<Section>, UICollectionViewDelegateFlowLayout {
typealias CellSize = (CollectionViewSectionedDataSource<Section>, UICollectionView, UICollectionViewLayout, IndexPath, Item) -> CGSize
typealias SizeViewInSection = (CollectionViewSectionedDataSource<Section>, UICollectionView, UICollectionViewLayout, Int, Section) -> CGSize
private var cellSize: CellSize
private var headerSectionViewSize: SizeViewInSection?
private var footerSectionViewSize: SizeViewInSection?
init(
configureCell: @escaping ConfigureCell,
configureSupplementaryView: ConfigureSupplementaryView? = nil,
moveItem: @escaping MoveItem = { _, _, _ in () },
canMoveItemAtIndexPath: @escaping CanMoveItemAtIndexPath = { _, _ in false },
cellSize: @escaping CellSize,
headerSectionViewSize: SizeViewInSection? = nil,
footerSectionViewSize: SizeViewInSection? = nil
) {
self.cellSize = cellSize
self.headerSectionViewSize = headerSectionViewSize
self.footerSectionViewSize = footerSectionViewSize
super.init(
configureCell: configureCell,
configureSupplementaryView: configureSupplementaryView,
moveItem: moveItem,
canMoveItemAtIndexPath: canMoveItemAtIndexPath
)
}
override func collectionView(
_ collectionView: UICollectionView,
observedEvent: Event<RxCollectionViewSectionedReloadDataSource<Section>.Element>
) {
collectionView.delegate = self
super.collectionView(collectionView, observedEvent: observedEvent)
}
func collectionView(
_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath
) -> CGSize {
cellSize(self, collectionView, collectionViewLayout, indexPath, self[indexPath])
}
func collectionView(
_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
referenceSizeForHeaderInSection section: Int
) -> CGSize {
headerSectionViewSize?(self, collectionView, collectionViewLayout, section, sectionModels[section]) ?? .zero
}
func collectionView(
_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
referenceSizeForFooterInSection section: Int
) -> CGSize {
footerSectionViewSize?(self, collectionView, collectionViewLayout, section, sectionModels[section]) ?? .zero
}
}
// swiftlint:enable line_length type_name