UIImageView Rotate Animation inside UITableViewCell

Viewed 1699

I'm trying to rotate an UIImage view on selecting row 0. On selection that section needs to reload to add two more cells. This is where the animation fails to work. The imageview just transforms to the new position without performing the animation.

      func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
            let cell = tableView.cellForRow(at: indexPath) as! CustomTableViewCell
            if indexPath.row == 0 {
                print(cell)
            }

            if displayCell {


                UIView.animate(withDuration:0.3, animations: {
                    cell.rotateButtonImageView.transform = CGAffineTransform(rotationAngle: CGFloat(0))
                })



                if indexPath.row != 0 {
                    swap(&indexArr[indexPath.row], &indexArr[0])
                    print(indexArr)
                }
            } else {

                UIView.animate(withDuration: 0.3, animations: {
                    cell.rotateButtonImageView.transform = CGAffineTransform(rotationAngle: (180.0 * .pi) / 180.0)
                })

            }

            displayCell = !displayCell

            tableView.reloadSections(IndexSet(integersIn: 0...0), with: .none)
    }

Also that particular cell at row = 0, the content needs to be updated. Here is a sample project:

1 Answers
Related