Creating custom view transitions
SwiftUI has a nice feature that gives us the possibility to add an animation when a view appears or disappears.
It is called Transition, and it can be animated with the usual degree of customization.
In this recipe, we'll see how to create custom appearing and disappearing transitions, combining different transitions.
Getting ready
This recipe uses two images courtesy of Erika Wittlieb (https://pixabay.com/users/erikawittlieb-427626/) from Pixabay (https://pixabay.com/).
You can find the images in the GitHub repo at https://github.com/PacktPublishing/SwiftUI-Cookbook/tree/master/Resources/Chapter07/recipe7, but you can also use your own images for this recipe.
Create a new SwiftUI project in Xcode called CustomViewTransitionApp
, and copy the ch7-r7-i1.jpg
and ch7-r7-i2.jpg
images in the Assets catalog:
How to do it…
We are going to...