gpt4 book ai didi

ios - UITableView.reloadRows 在 Timer.scheduledTimer 内部调用时重置行动画类型

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:58:05 25 4
gpt4 key购买 nike

我正在寻找具有 RowAnimation 类型 'bottom' 的延迟行动画,并具有将行推送到 TableView 的特定持续时间。

到目前为止,我找到了两个选项:

  1. UIView.transition中调用UITableView.reloadRows设置动画时长,在Timer.scheduledTimer UIView.transition设置延迟:
Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { _ in
UIView.transition(with: self.tableView,
duration: 1.0,
animations: {
self.tableView.reloadRows(at: [indexPath], with: .bottom)
}, completion: nil)
}

这种方式动画持续时间没问题,但是 RowAnimation 类型被重置(我想从 '.bottom' 到 '.automatic')。

  1. 使用CATransaction做带时长的动画,在Timer.scheduledTimer中调用它来设置延迟:
Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { _ in
CATransaction.begin()
CATransaction.setAnimationDuration(1)

self.tableView.reloadRows(at: [indexPath], with: .bottom)

CATransaction.commit()
}

这种方式 RowAnimation 类型是可以的,但是动画持续时间不被尊重。

如何正确设置 RowAnimation 类型不被重置或 CATransaction 的动画持续时间延迟?

最佳答案

使用 main DispatchQueue 的asyncAfter(deadline:,qos:,flags:,execute) 方法所以,

DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {[weak self] in
UIView.animate(withDuration: 1.0, animations: {
self?.tableView.reloadRows(at: [indexPath], with: .bottom)
})
}

根据您的要求添加您想要的任何延迟。我在这里使用了 1.0 秒。

关于ios - UITableView.reloadRows 在 Timer.scheduledTimer 内部调用时重置行动画类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57752944/

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