Refactoring existing animations with UIViewPropertyAnimator
So far, you have seen animations that were implemented using the UIView.animate
method. These animations are quite simple to implement and mostly follow the following format:
UIView.animate(withDuration: 1.5, animations: { myView.backgroundColor = UIColor.red() })
You have already seen this method implemented in slightly more complex ways, including one that used a closure that was executed upon completion of the animation. For instance, when a user taps on one of the contacts in the Hello-Contacts app, the following code is used to animate a bounce effect:
UIView.animate(withDuration: 0.1, delay: 0, options: [.curveEaseOut], animations: { cell.contactImage.transform = CGAffineTransform(scaleX: 0.9, y: 0.9) }, completion: { finished in UIView.animate(withDuration: 0.1, delay: 0, options: [.curveEaseIn], animations: { cell.contactImage.transform = CGAffineTransform.identity ...