help in animating table view once

Hey guys I am trying a fade animation on table view, the table view rows are supposed to render one after the other while fading in
func animate(_ cell: UITableViewCell, _ index: Int) {
cell.alpha = 0
animator = UIViewPropertyAnimator(duration: 0.3 * Double(index), curve: .easeIn) {
cell.alpha = 1
}
animator?.startAnimation(afterDelay: 1.5)
}

func stopAnimation() {
animator?.stopAnimation(true)
}


func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
animate(cell, indexPath.item)
}
func animate(_ cell: UITableViewCell, _ index: Int) {
cell.alpha = 0
animator = UIViewPropertyAnimator(duration: 0.3 * Double(index), curve: .easeIn) {
cell.alpha = 1
}
animator?.startAnimation(afterDelay: 1.5)
}

func stopAnimation() {
animator?.stopAnimation(true)
}


func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
animate(cell, indexPath.item)
}
I am using the code above, the current problem is every time I scroll table the cells start animating PS: I have tried using a boolean variable in in viewDidLoad and passing it to check whether the animation should stop but, yet it doesn' t work
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?