Setting up the ContentView for animation
Here, in the ContentView
, we are ready to use the wave shape and add the animation to it. Let’s start by creating a new struct at the bottom of the file, just above the Previews
struct, and call it WaveCreation
:
struct WaveCreation: View { var body: some View { } }
This struct is very similar to the ContentView
struct – it conforms to the View
protocol, which means it must implement the body
property. The body
property itself will return a view, and that will be the animated wave. By the end of the next section, we will have created six waves in total, spaced out neatly inside of a stack.
We will need several variables to get this working, some for the animation and some that allow us to alter the size of the wave curve. Add the following code above the body
property, inside the WaveCreation
struct:
@Binding var animateOffset: Bool var curveOne...