UitableView Cell Load with animation

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

        //1. Setup the CATransform3D structure

        var rotation = CATransform3D()

        rotation = CATransform3DMakeRotation((90.0 * .pi) / 180, 0.0, 0.7, 0.4)

        rotation.m34 = 1.0 / -600

        //2. Define the initial state (Before the animation)

        cell.layer.shadowColor = UIColor.black.cgColor

        cell.layer.shadowOffset = CGSize(width: CGFloat(10), height: CGFloat(10))

        cell.alpha = 0

        cell.layer.transform = rotation

        cell.layer.anchorPoint = CGPoint(x: CGFloat(0), y: CGFloat(0.5))

        //!!!FIX for issue #1 Cell position wrong————

        if cell.layer.position.x != 0 {

            cell.layer.position = CGPoint(x: CGFloat(0), y: CGFloat(cell.layer.position.y))

        }

        //4. Define the final state (After the animation) and commit the animation

        UIView.beginAnimations(“rotation”, context: nil)

        UIView.setAnimationDuration(0.8)

        cell.layer.transform = CATransform3DIdentity

        cell.alpha = 1

        cell.layer.shadowOffset = CGSize(width: CGFloat(0), height: CGFloat(0))

        UIView.commitAnimations()

    }

Leave a comment