Ios 转换不能与SwiftUI中的路由器一起工作

Ios 转换不能与SwiftUI中的路由器一起工作,ios,swift,iphone,swiftui,Ios,Swift,Iphone,Swiftui,我正在制作一个基于SwiftUI的应用程序 我在主层次结构中嵌入了一个路由器来管理应用程序导航。开始时,这是工作良好,但后来我添加了第二级路由器和过渡被打破,并停止工作 实际上,两个路由器中的导航都工作得很好,但无法使其与转换一起工作 应用程序根目录转到以下文件: var body: some View { VStack { if authRouter.isFirstLaunch { AuthView() } else if ses

我正在制作一个基于SwiftUI的应用程序

我在主层次结构中嵌入了一个路由器来管理应用程序导航。开始时,这是工作良好,但后来我添加了第二级路由器和过渡被打破,并停止工作

实际上,两个路由器中的导航都工作得很好,但无法使其与转换一起工作

应用程序根目录转到以下文件:

var body: some View {
    VStack {
        if authRouter.isFirstLaunch {
            AuthView()
        } else if sessionState.launchListeningCompleted || sessionState.user != nil || sessionState.error != nil {
            Home()
        } else {
            ZStack {
                Image("Icon")
                VStack {
                    Spacer()
                    ActivityIndicatorUI(animating: .constant(true), style: .medium)
                        .padding(.bottom)
                    Image("Launcher")
                        .padding(.bottom, 95.0)
                        .padding(.top)
                }
            }
        }
    }.onAppear(perform: isFirstLaunch)
}
基本上,如果是第一次启动应用程序,它将转到AuthView文件,该文件是一个路由器,如下所示:

struct AuthView: View {

@EnvironmentObject var authRouter: AuthRouter

var body: some View {
    VStack {
        if authRouter.viewName == AuthViews.Onboarding {
            Onboarding()
        } else if authRouter.viewName == AuthViews.SignIn {
            SignIn()
                .transition(.scale)
        } else if authRouter.viewName == AuthViews.SignUp {
            SignUp()
                .transition(.move(edge: .trailing))
        } else if authRouter.viewName == AuthViews.ForgotPassword {
            ForgotPassword()
                .transition(.move(edge: .trailing))
        }
    }
}
}

这些转变不起作用。开始时,这是我添加的第一个路由器,它正在工作。然后在第二级,它停止工作


谢谢你的帮助

将动画添加到父容器

var body: some View {
    VStack {
        if authRouter.viewName == AuthViews.Onboarding {
            Onboarding()
        } else if authRouter.viewName == AuthViews.SignIn {
            SignIn()
                .transition(.scale)
        } else if authRouter.viewName == AuthViews.SignUp {
            SignUp()
                .transition(.move(edge: .trailing))
        } else if authRouter.viewName == AuthViews.ForgotPassword {
            ForgotPassword()
                .transition(.move(edge: .trailing))
        }
    }.animation(.default)     // << here !! (any animation you like)
}
var主体:一些视图{
VStack{
如果authRouter.viewName==AuthViews.Onboard{
入职()
}如果authRouter.viewName==AuthViews.SignIn,则为else{
签名()
.转换(.scale)
}否则,如果authRouter.viewName==AuthViews.SignUp{
注册()
.transition(.move(边:。尾部))
}否则,如果authRouter.viewName==AuthViews.ForgotPassword{
放弃密码()
.transition(.move(边:。尾部))
}

}.animation(.default)/将动画添加到父容器

var body: some View {
    VStack {
        if authRouter.viewName == AuthViews.Onboarding {
            Onboarding()
        } else if authRouter.viewName == AuthViews.SignIn {
            SignIn()
                .transition(.scale)
        } else if authRouter.viewName == AuthViews.SignUp {
            SignUp()
                .transition(.move(edge: .trailing))
        } else if authRouter.viewName == AuthViews.ForgotPassword {
            ForgotPassword()
                .transition(.move(edge: .trailing))
        }
    }.animation(.default)     // << here !! (any animation you like)
}
var主体:一些视图{
VStack{
如果authRouter.viewName==AuthViews.Onboard{
入职()
}如果authRouter.viewName==AuthViews.SignIn,则为else{
签名()
.转换(.scale)
}否则,如果authRouter.viewName==AuthViews.SignUp{
注册()
.transition(.move(边:。尾部))
}否则,如果authRouter.viewName==AuthViews.ForgotPassword{
放弃密码()
.transition(.move(边:。尾部))
}

}.animation(.default)//您知道为什么在开始时没有.animation(),或者什么时候使用它,什么时候避免它吗?谢谢。这个建议工作得很好。您知道为什么在开始时没有.animation(),或者什么时候使用它,什么时候避免它吗?谢谢。这个建议工作得很好。