gpt4 book ai didi

ios - 调用reloadSections后UITableView跳转 :withRowAnimation:

转载 作者:可可西里 更新时间:2023-11-01 03:32:48 33 4
gpt4 key购买 nike

<分区>

我需要展开/折叠 UITableView 的一部分。我通过调用 reloadSections:withRowAnimation: 并从 tableView:numberOfRowsInSection: 返回 0 来实现这一点:如果该部分应该折叠。

除一种情况外,它工作正常。如果 table view 一直向下滚动并且内容大小在折叠后减小,它最终会滚动到超过最大偏移量。现在它不再使用动画滚动到位,它只是捕捉到那里,看起来很难看:

enter image description here

这是我尝试过的:

  1. beginUpdates/endUpdates 中包装 reloadSections:withRowAnimation::

    tableView.beginUpdates()
    tableView.reloadSections(indexSet, withRowAnimation: .Automatic)
    tableView.endUpdates()

    那没有帮助。

  2. 用完成 block 将reloadSections:withRowAnimation:包裹在CATransaction中,计算其中的滚动距离并用动画滚动表格 View :

    CATransaction.begin()
    CATransaction.setCompletionBlock {
    // tableView.contentSize is incorrect at this point
    let newContentOffset = ... // calculated value is not correct
    tableView.setContentOffset(newContentOffset, animated: true)
    }

    tableView.beginUpdates()
    tableView.reloadSections(indexSet, withRowAnimation: .Automatic)
    tableView.endUpdates()
    CATransaction.commit()

如何确保表格 View 不跳转?

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com