Understanding the concept of SwiftUI animations
For a developer coming from UIkit and taking their first steps in SwiftUI, the concept of writing animations in a declarative framework could feel a little awkward. After all, performing animations in UIkit was extremely simple – all we had to do was respond to some event and change some view properties within an animation closure. Here’s a simple example of how to fade out a view in UIkit:
UIView.animate(withDuration: 2.0, animations: { sampleView.alpha = 0.0 }) { (finished) in }
In this example, we modify the alpha level of sampleView
inside a UIView
animation closure.
While this looks pretty simple, it comes with a significant drawback – the need to sync the animation action to the screen state. The sampleView
component is now hidden – but does that mean that our view model or any...