How to animate particular table View cell

Viewed 162

I have a table view that has 4 cells. And I want to hide first two cell for few second And i am doing this -:

   func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    if historyArray.count > 0 {
        cell.alpha = 0
        if indexPath.row == 0 || indexPath.row == 1 {
        UIView.animate(
            withDuration: 1,
            delay: 0.05 * Double(indexPath.row),
            animations: {
                cell.alpha = 1
        })
    }
    }

but this code has not worked for me. how to do this.

1 Answers

can u pls try this

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        
        if indexPath.row == 0 || indexPath.row == 1 {
            cell.transform = CGAffineTransform(translationX: self.view.frame.width, y: 0)
            UIView.animate(withDuration: 1) {
                cell.transform = .identity
            }
        }
    }
Related