2

I'm looking for delayed row animation with RowAnimation type 'bottom' and with specific duration for pushing rows to table view.

So far I found two options:

  1. Call UITableView.reloadRows inside UIView.transition to set animation duration, call UIView.transition inside Timer.scheduledTimer to set the delay:
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)
}

This way animation duration is OK, but RowAnimation type is reset (from '.bottom' I suppose to '.automatic').

  1. Use CATransaction for animation with duration, and call it inside Timer.scheduledTimer to set the delay:
Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { _ in
    CATransaction.begin()
    CATransaction.setAnimationDuration(1)

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

    CATransaction.commit()
}

This way RowAnimation type is OK, but animation duration is not respected.

How to set up properly either the RowAnimation type not to be reset or the animation duration for CATransaction with delay?

1 Answers1

0

Use main DispatchQueue's, asyncAfter(deadline:,qos:,flags:,execute) method like so,

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

Add whatever delay you want as per your requirement. I used 1.0 second here.

PGDev
  • 23,751
  • 6
  • 34
  • 88
  • Tried it already, same result as with timer (also note you didn't take into account animation duration). – Raman Shestakou Sep 02 '19 at 07:39
  • @peter This approach has the issue mentioned in question title - ```RowAnimation``` is reset, and the cell is animated with fade + some controls movements, so I believe it's **'.automatic'**. – Raman Shestakou Sep 02 '19 at 08:05