Performing basic animations
The fundamental way to understand how SwiftUI animations work is by associating a state value with a particular animation flow.
There are three ways of performing basic animations in SwiftUI:
- Using the
animation
modifier – adding an animation to a specific view - Using the
withAnimation
global function – performing animation by changing several states - Using
animation()
method – attaching an animation to a binding value
Developers usually get confused and think there’s some duplication here – separate ways to perform the same functionality. But the truth is that all three serve different purposes and needs. It’s up to us to decide the suitable way, according to our specific code structure and flow. Sometimes, you want to perform a particular animation to a specific view; occasionally, it is a shared experience with several views. Understanding the different use cases can help us decide how...