LAST CHANCE: Save 50% on all my Swift books and bundles! >>

Animation problem/bug

Forums > SwiftUI

Hello developers,

I'm using .hueRotation in my code, but I have a little experience with animations and I want to ask if theres some bug in the code or it's the bug of the SwiftUI

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationStack {
            VStack {
                Spacer()
                VStack(spacing: 16) {
                    Text("WELCOME")
                    Text("TO")
                    Text("THE")
                }
                .font(.largeTitle)
                .fontWeight(.heavy)

                NavigationLink {
                    EmptyView()
                } label: {
                    Text("APP")
                        .font(.system(size: 60, weight: .heavy))
                        .foregroundStyle(.blue)
                        .phaseAnimator([false, true]) { content, rotate in
                            content
                                .hueRotation(.degrees(rotate ? 100 : 20))
                        } animation: { rotate in
                                .easeInOut(duration: 1)
                        }
                }
                .buttonStyle(.bordered)

                Spacer()

                VStack(spacing: 20){
                    Text("Already have an account ?")
                        .font(.callout)
                    NavigationLink {
                        EmptyView()
                    } label: {
                        Text("Log in")
                            .foregroundStyle(.blue)
                            .phaseAnimator([false, true]) { content, rotate in
                                content
                                    .hueRotation(.degrees(rotate ? 100 : 20))
                            } animation: { rotate in
                                    .easeInOut(duration: 1)
                            }
                    }
                    .buttonStyle(.bordered)
                }
            }
        }
    }
}

#Preview {
    NavigationStack {
        ContentView()
    }
}

Try and run this code in a simulator (in preview everything works fine).

The big APP won't change colors at first but when you tap on it and go back it'll start to work as it should.

Do I have something wrong in the code ? Because the Log in works normal when I run the app...

Thanks for help 🙂

   

Hacking with Swift is sponsored by Essential Developer.

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until July 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.