Загрузка видео...

Не удалось загрузить видео

На главную

I've started meditating again after a while. 🧘🏼 So, naturally, I wanted to copy the Headspace app's loading animation. I spent way too much time rebuilding it using #SwiftUI. I tried improving it (original in comment), let me know Headspace if you need access to the code.😇

93,359 просмотров • 1 год назад •via X (Twitter)

Комментарии: 36

Фото профиля Stefan
Stefan1 год назад

Here's the original animation:

Фото профиля Qodo (formerly Codium)
Qodo (formerly Codium)1 год назад

Make code reviews seamless with Qodo Merge. Directly implement changes to PRs, apply modifications from review comments, and fine-tune updates using intelligent suggestions. Let Qodo Merge learn and adapt to your team’s best practices for better results.

Фото профиля Sean Kelly
Sean Kelly1 год назад

Had a go at the animation part, here's my effort: import SwiftUI struct ContentView: View { @State private var scale: CGFloat = 0.1 @State private var yOffset: CGFloat = 0 @State private var breatheIn = false @State private var animationStarted = false var body: some View { GeometryReader { geometry in ZStack { Color(UIColor.systemIndigo).ignoresSafeArea() ZStack { Circle() .fill( .frame(width: geometry.size.width * 0.8, height: geometry.size.width * 0.8) .scaleEffect(scale * (breatheIn ? 1.6 : 1.1)) FaceView(breatheIn: breatheIn) .frame(width: geometry.size.width * 0.4, height: geometry.size.width * 0.4) .offset(y: -geometry.size.height * 0.3) .scaleEffect(scale * (breatheIn ? 0.8 : 0.6)) } .offset(y: yOffset + (breatheIn ? -geometry.size.height * 0.1 : 0)) } .onAppear { withAnimation(.easeInOut(duration: 2)) { scale = 1.5 yOffset = geometry.size.height * 0.45 } DispatchQueue.main.asyncAfter(deadline: .now() + 2) { animationStarted = true withAnimation(Animation.easeInOut(duration: 4).repeatForever(autoreverses: true)) { breatheIn.toggle() } } } } } } struct FaceView: View { var breatheIn: Bool let strokeWidth: CGFloat = 0.08 var body: some View { GeometryReader { geometry in ZStack { // Eyes EyeView() .stroke( style: StrokeStyle(lineWidth: geometry.size.width * strokeWidth, lineCap: .round, lineJoin: .round)) .frame(width: geometry.size.width, height: geometry.size.height * 0.4) .position(x: geometry.size.width / 2, y: geometry.size.height * 0.4) // Smile SmileShape(progress: breatheIn ? 1 : 0) .stroke( style: StrokeStyle(lineWidth: geometry.size.width * strokeWidth, lineCap: .round, lineJoin: .round)) .frame(width: geometry.size.width, height: geometry.size.height * 0.6) .position(x: geometry.size.width / 2, y: geometry.size.height * 0.7) .animation(.easeInOut(duration: 4).repeatForever(autoreverses: true), value: breatheIn) } } } } struct EyeView: Shape { func path(in rect: CGRect) -> Path { var path = Path() let width = rect.width let height = rect.height // Left eye path.move(to: CGPoint(x: width * 0.2, y: height * 0.5)) path.addQuadCurve( to: CGPoint(x: width * 0.4, y: height * 0.5), control: CGPoint(x: width * 0.3, y: height * 0.3) ) // Right eye path.move(to: CGPoint(x: width * 0.6, y: height * 0.5)) path.addQuadCurve( to: CGPoint(x: width * 0.8, y: height * 0.5), control: CGPoint(x: width * 0.7, y: height * 0.3) ) return path } } struct SmileShape: Shape { var progress: CGFloat var animatableData: CGFloat { get { progress } set { progress = newValue } } func path(in rect: CGRect) -> Path { var path = Path() let width = rect.width let height = rect.height let smileWidth = 0.4 + (0.6 * progress) let smileHeight = 0.55 + (0.55 * progress) let startX = width * ((1 - smileWidth) / 2) let endX = width * (1 - (1 - smileWidth) / 2) path.move(to: CGPoint(x: startX, y: height * 0.6)) path.addQuadCurve( to: CGPoint(x: endX, y: height * 0.6), control: CGPoint(x: width * 0.5, y: height * smileHeight) ) return path } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }

Фото профиля Anum 
Anum 1 год назад

@Headspace Wow thats pretty neat!

Фото профиля Stefan
Stefan1 год назад

@Headspace Thanks a lot. Really enjoyed building out that one.

Фото профиля Simon Auer
Simon Auer1 год назад

@Headspace Looking very good though! Nice work!

Фото профиля Stefan
Stefan1 год назад

@Headspace Thank you, Simon!

Фото профиля Satyendra Mourya
Satyendra Mourya1 год назад

@Headspace I sometimes wonder how I can do this on the web.

Фото профиля Stefan
Stefan1 год назад

@Headspace That is an excellent question. In my experience, keyframe animations can get you quite far: But for these more complex ones, I have achieved great results with @framer motion:

Фото профиля Lusine Magauzyan
Lusine Magauzyan1 год назад

@Headspace Looks amazing! Not Headspace but wud love access to the code 😅

Фото профиля Patrick Freyer
Patrick Freyer1 год назад

@Headspace Did you use Xcode 16 yet? Curious whether those AI features did any good to your project!

Фото профиля Stefan
Stefan1 год назад

@Headspace I did use Xcode 16, but not any of the AI features. I'm not sure why the Autocomplete doesn't work for me yet. Maybe I missed activating it at some point. 😇 But to answer your question, there was no AI help for this one.

Фото профиля Beatriz Cunha
Beatriz Cunha1 год назад

@Headspace really good! I just felt the breathing is a bit too fast, but maybe it's the video speed. great stuff!

Фото профиля Stefan
Stefan1 год назад

@Headspace Thank you! Yes, you might be right. It could indeed be a bit slower. The problem is that you're never finished with an animation like this. So, at some point, I just needed to say, "It's good enough," and at least share it. But good catch!

Фото профиля aboghaly 🇵🇸
aboghaly 🇵🇸1 год назад

@Headspace 👏👏👏👏👏

Фото профиля Amir Dev
Amir Dev1 год назад

@Headspace That animation looks awesome! Did rebuilding it in SwiftUI end up being more relaxing than meditating? 😄

Фото профиля Stefan
Stefan1 год назад

@startdustdev @Headspace Haha, thank you. And the creation of the animation was not more relaxing than a meditation. However, I can get into a very focused state while working on things like that, which probably has a therapeutic effect to some degree. :)

Фото профиля Pencil
Pencil1 год назад

I would love to see the code, pls

Фото профиля wophb
wophb1 год назад

@Headspace That's awesome, Stefan! Your dedication to meditating and then taking the time to rebuild the animation in SwiftUI is really inspiring. Would love to see more of your creative projects!

Фото профиля Stefan
Stefan1 год назад

@Headspace Thank you! I will share more of the experiments I'm building and even plan to turn some of them into tutorials to share the techniques used for others to learn. :)

Фото профиля Khoa 🔥
Khoa 🔥1 год назад

@Headspace It looks great Stefan

Фото профиля Stefan
Stefan1 год назад

@Headspace Thanks Khoa, I definitely went the extra mile here. But it was just so much fun. :)

Фото профиля Marco Peñuelas 🔴
Marco Peñuelas 🔴1 год назад

@Headspace Genial !

Фото профиля Piotr 💻
Piotr 💻1 год назад

@Headspace Great animation 🔥

Фото профиля Jan Stehlík
Jan Stehlík1 год назад

@Headspace I'm not headspace but I need the code 😀

Фото профиля Harshvardhan Trivedi
Harshvardhan Trivedi1 год назад

@Headspace Looks Awesome!

Фото профиля Kҽʋιɳ Sҽɾɾαɳσ
Kҽʋιɳ Sҽɾɾαɳσ1 год назад

@Headspace Nice 🤩

Фото профиля Chris Wakefield 彡👾
Chris Wakefield 彡👾1 год назад

@Headspace Wow! This is awesome!

Фото профиля Senior Ngenge
Senior Ngenge1 год назад

@Headspace Where is the link to your SwiftUI course? 😂😂

Фото профиля Frank Junior
Frank Junior1 год назад

@Headspace Please share the code to let usl learning the animation thank you

Фото профиля Piyush Pandey (PiYu)
Piyush Pandey (PiYu)1 год назад

@Headspace Looks Amazing @stefanjblos ... How can I do it in Android...

Фото профиля Salvador
Salvador1 год назад

@Headspace Wonder if I could replicate it using react native reanimated 🤔

Фото профиля Abdullah Ajmal
Abdullah Ajmal1 год назад

@Headspace Smoothhhh! 🔥

Фото профиля Alperen Sarışan
Alperen Sarışan1 год назад

@Headspace Wow this is really nice. If I was one of the users, I’d create that account. Also thank you for sharing the code

Фото профиля brother ahmet
brother ahmet1 год назад

@Headspace looks really nice!

Фото профиля Wilbur
Wilbur1 год назад

@Headspace Love the animation

Похожие видео