如何仅在 ona indexPath 使布局无效?

问题描述

我有一个包含带有按钮的单元格的集合。

Short Cell Long Cell

通过单击这些按钮,单元格高度会增加。为此,我调用了 collectionView.invalidateLayout(),但我注意到在此方法之后,cellForItemAt 被调用了 4 次,尽管我只需要重载一个缩进(从增加的单元格底部开始)。

现在代码是这样的:

func setAndReload(cellMode: EventCellMode,at indexPath: IndexPath) {
    data[indexPath.item].mode = cellMode
    let offset = collectionView.contentOffset
    let cell = self.collectionView.cellForItem(at: indexPath) as! ShortEventCollectionViewCell
    cell.set(mode: cellMode)

    UIView.performWithoutAnimation {
        DispatchQueue.main.async {
            self.collectionView.collectionViewLayout.invalidateLayout()
            self.collectionView.layoutIfNeeded()
            self.collectionView.setContentOffset(offset,animated: false)
        }
    }
}

如何确保我的所有单元格都不会超载?我听说这可以在 UICollectionViewLayoutInvalidationContext 的帮助下完成,但我没有找到实现。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)