Swiftui 为什么我不';用户登录时是否看不到我的动画?

Swiftui 为什么我不';用户登录时是否看不到我的动画?,swiftui,uiviewanimation,onappear,Swiftui,Uiviewanimation,Onappear,我创建了一个自定义的LaunchsRen,当用户未登录时,它工作得很好,但是如果用户登录,我们就看不到动画(视图直接进入主视图,不等待动画完成) 你知道为什么吗 import SwiftUI struct LaunchScreen: View { @EnvironmentObject var session: SessionStore @State private var animationDone = false @State private var rotation

我创建了一个自定义的LaunchsRen,当用户未登录时,它工作得很好,但是如果用户登录,我们就看不到动画(视图直接进入主视图,不等待动画完成)

你知道为什么吗

import SwiftUI

struct LaunchScreen: View {
    @EnvironmentObject var session: SessionStore
    @State private var animationDone = false
    @State private var rotation = 0.0
    
    func getUser () {
        session.listen()
    }
    
    var body: some View {
        Group{
            if (session.session != nil && animationDone) {
                Home()
            }
            else if (session.session == nil && animationDone) {
                Login()
            }
            else {
                ZStack {
                    Color(#colorLiteral(red: 0.259467423, green: 0.5342320204, blue: 0.7349982858, alpha: 1))
                    VStack {
                        HStack (alignment: .center, spacing: 0, content: {
                            
                            Text("Se")
                                .foregroundColor(.white)
                                .font(.system(size: 40))
                            Text("e")
                                .foregroundColor(.white)
                                .font(.system(size: 40))
                                .rotation3DEffect(Angle(degrees: rotation), axis: (x: 0, y: 1, z: 0))
                        })
                    }
                }.edgesIgnoringSafeArea(.all)
            }
        }
        .onAppear{
            withAnimation(Animation.easeInOut(duration: 1)){
                rotation += 180
            }
            withAnimation(Animation.linear.delay(1.5)){
                animationDone = true
            }
        }
        .onAppear(perform: getUser)
    }
}


在这种情况下,解决方案是使用
DispatchQueue
延迟,如

    }
    .animation(.linear, value: animationDone)             // << this !!
    .onAppear{
        withAnimation(Animation.easeInOut(duration: 1)){
            rotation += 180
        }
        DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
            animationDone = true                         // << and this !!
        }
    }
}

.animation(.linear,value:animationDone)//因为Home位于条件的顶部,所以只有在所有条件都不满足时才能看到飞溅。如果你想运行你的飞溅无论什么,把它从条件和/或把它放在顶部。嗯,它不工作,动画是打破了你的建议。。。