Creating floating hearts in SwiftUI
When Periscope was introduced in 2015, it was the first app to popularize the live-streaming feature that is now part of other apps, such as Facebook, Instagram, and YouTube.
A way of appreciating the streamer was to send a bunch of floating hearts, a feature that is also now implemented on Instagram and Facebook.
In this recipe, we'll see how to implement this feature in SwiftUI, as an example of a fairly complex real-world animation that can still be done easily in SwiftUI.
Getting ready
Let's start by creating a SwiftUI app called FloatingHeartsApp
.
For this recipe, we are going to use a third-party framework that provides a function to create an interpolation when given a small set of points.
The library is called SwiftCubicSpline
and can be found at https://github.com/gscalzo/SwiftCubicSpline:
- From the menu, select Files | Swift Packages | Add Package Dependency...: