Table view cell load animation one after another

Andrea Mario Lufino picture Andrea Mario Lufino · Oct 29, 2015 · Viewed 19.7k times · Source

I need to animate the load of the table view rows. When the table reloads the data I need the rows get in from the left one after another. How can I achieve this?

Answer

Ahmadreza picture Ahmadreza · Mar 30, 2018

Swift 4

Add this little cute extension

extension UITableView {    

    func reloadWithAnimation() {
        self.reloadData()
        let tableViewHeight = self.bounds.size.height
        let cells = self.visibleCells
        var delayCounter = 0
        for cell in cells {
            cell.transform = CGAffineTransform(translationX: 0, y: tableViewHeight)
        }
        for cell in cells {
            UIView.animate(withDuration: 1.6, delay: 0.08 * Double(delayCounter),usingSpringWithDamping: 0.6, initialSpringVelocity: 0, options: .curveEaseInOut, animations: {
                cell.transform = CGAffineTransform.identity
            }, completion: nil)
            delayCounter += 1
        }
    }
}

Then, instead of "tableView.reloadData()", use "tableView.reloadWithAnimation()"