Recreating the Apple Music App Animations with SwiftUI

Learn how to recreate the Apple Music Animation with SwiftUI, using matchedGeometryEffect

ML Musings
1 min readJan 22, 2023

I wrote these little pieces of code using SwiftUI and Swift Playgrounds on an iPad.

Code

import SwiftUI

struct AppleMusicAnimation: View {
@State var show = false
@Namespace var namespace

var body: some View {
VStack {
Spacer()
VStack (spacing: 15) {
HStack (spacing: 15) {

Image("photos").resizable().aspectRatio(contentMode: .fit).frame(width: self.show ? 350 : 50, height: self.show ? 350 : 50).padding(.top, self.show ? 40 : 0)

if !self.show {
VStack (alignment: .leading, spacing: 4) {
Text("Title")
}.matchedGeometryEffect(id: "Title", in: self.namespace)

Spacer()

Button(action: {}) {
Image(systemName: "play.fill").font(.title).foregroundColor(.black)
}.matchedGeometryEffect(id: "Play", in: self.namespace)

Button(action: {}) {…

--

--

ML Musings

✨ I enjoy pushing the boundaries of JS, Python, SwiftUI and AI. You can support my work through coffee - www.buymeacoffee.com/MLMusings