2

我正在寻找“底部”RowAnimation类型的延迟行动画,并且具有将行推送到表格视图的特定持续时间。

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

  1. UITableView.reloadRows内部调用UIView.transition设置动画时长,调用UIView.transition内部Timer.scheduledTimer设置延迟:
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时间?

4

1 回答 1

0

像这样使用main DispatchQueue'sasyncAfter(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 秒。

于 2019-09-02T07:33:58.873 回答