Adding the wave’s offset property
Okay, let’s start by creating a new SwiftUI project – I’ll be calling it Making Waves
.
Then, let’s add a new file that will be in charge of making the waves for the ocean. Press Command + N to create a new file, then select the SwiftUIView file, and call it WaveView
.
Inside this new file, we will make some minor modifications to the structure so that it conforms to the Shape protocol, as we did in the previous project. So, at the top of the WaveView
struct, right after its name, remove the View
protocol and replace it with the Shape
protocol. Also, remove the body
property as we don’t need that here. The file should look like this:
struct WaveView: Shape { }
The reason why we removed the body
property was that it was used to return a view; however, we will be returning a path
variable that will hold the shape of the wave we want to animate.
The animation we want to create will be a wavy line...