gpt4 book ai didi

swift - ScrollToRowAtIndexPath 花费太多时间

转载 作者:行者123 更新时间:2023-11-30 12:08:54 26 4
gpt4 key购买 nike

我正在尝试滚动表格以显示最后一个单元格。我正在使用 scrollToRowAtIndexPath 底部方法,但它花费了太多时间。我该如何解决这个问题?

最佳答案

要使用自定义时间制作动画,您可以使用以下代码:

tableView.layoutIfNeeded()
var offset = tableView.contentSize.height

let offsetPoint = CGPoint(x: 0, y: offset)

UIView.animate(withDuration: 0.1, animations: {
tableView.setContentOffset(offsetPoint, animated:false)
})

然后您可以将 0.1 替换为您想要为滚动设置动画的秒数。

编辑:

如果您不想要任何动画,也可以尝试:

let lastSectionIndex = tableView.numberOfSections() - 1
let lastRowIndex = tableView.numberOfRows(inSection: lastSectionIndex) - 1

tableView.scrollToRow(at: IndexPath(row: lastRowIndex, section: lastSectionIndex), at: .top, animated: false)

关于swift - ScrollToRowAtIndexPath 花费太多时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46324567/

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