首页 > 解决方案 > 动画调整大小的单元格下方的单元格以一种奇怪的方式跳跃

问题描述

我正在尝试制作一个可扩展单元格,其高度由其内部的约束定义,称为backHighlightHeight. 但我得到了这个

我尝试过很多方法,但我认为应该按预期工作的方式是这样的:

didSelectRowAt

if let tappedCell = tableView.cellForRow(at: indexPath) as? WorkoutCell {
    if let index = self.collapsedIndexPaths.firstIndex(of: indexPath) {
        self.collapsedIndexPaths.remove(at: index)
        tappedCell.showSets(true)
        self.tableView.beginUpdates()
        self.tableView.endUpdates()
    } else {
        self.collapsedIndexPaths.append(indexPath)
        tappedCell.showSets(false)
        self.tableView.beginUpdates()
        self.tableView.endUpdates()
    }
}

内部WorkoutCell

func showSets(_ show: Bool) {
    if show {
        backHighlightHeight.constant = 200
    } else if !show {
        backHighlightHeight.constant = 64
    }
}

在调用的单元格方法内部,cellForRow还有正确设置高度的逻辑。

标签: swiftanimationtableview

解决方案


推荐阅读