Animating a cell more than once

I have a uitableview cell and it will show when the cell is displayed. These cells are in table views and these tables are tabs of the uitabbarcontroller. But if the user clicks one of the four tabs for the first time, the cells will animate, but if the user clicks a new tab and returns to the previous tab, the cells will not animate. How can I make it so that the cells animate every time the table view is displayed. Here is my code, can someone please show me how I can make the cell animated every time the view is presented, not just the cell is displayed.

override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {

        let rotationTransform = CATransform3DScale(CATransform3DIdentity, 10, 10, 0)
        cell.layer.transform = rotationTransform
        UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.2, initialSpringVelocity: 0.1, options: .curveEaseOut, animations: {
            cell.layer.transform = CATransform3DIdentity
        }, completion: nil)
}

      

+3


source to share


1 answer


Refresh data will display the controller method:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    tableview.reloadData()
}

      

Also, a reset may be required before re-animating. What for? because when you view the table view, the cells that appear will not be displayed. they will have a final state after animation (reusable cells).



One more thing you can hack and the top cell will disappear before the animation finishes. I'm not sure what will happen. it may not take its final state. and when you go back to it or that cell is used again, the cell will not have a final state. but if you reset to the first state before starting the animation again that will solve all problems.

reset animation:

cell.layer.transform = nil
// you may need to layout the cell. not sure. after this.
// then the rest of your code that animates the cell.

      

+3


source







All Articles