什么时候设置更改heightForRowAt UITableView动画被破坏

问题描述 投票:3回答:1

什么时候设置改变heightForRowAt UITableView动画被破坏的单元格是一个跳跃。如果选择最后一行并在顶部滚动,则在点击折叠行后,表格将跳至上方。动画破了。

enter image description here

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.delegate = self
    tableView.dataSource = self
    tableView.estimatedRowHeight = 300
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return conditionData[indexPath.section].conditions?[indexPath.row].selected ?? false ? 300 : 76
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    conditionData[indexPath.section].conditions?[indexPath.row].selected = true
    tableView.beginUpdates()
    let cell = tableView.cellForRow(at: indexPath) as? ConditionsCell
    cell?.setSelected(true, animated: true)
    tableView.endUpdates()
}

func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
    conditionData[indexPath.section].conditions?[indexPath.row].selected = false
    tableView.beginUpdates()
    let cell = tableView.cellForRow(at: indexPath) as? ConditionsCell
    cell?.setSelected(false, animated: true)
    tableView.endUpdates()
}
ios swift uitableview uiviewanimation
1个回答
0
投票

当我开始使用此方法时,动画看起来非常好。

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return conditionData[indexPath.section].conditions?[indexPath.row].selected ?? false ? 300 : 76
}
© www.soinside.com 2019 - 2024. All rights reserved.