我正在制作一个基于 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)
}
并确保authRouter.viewName
始终在 上更新DispatchQueue.main
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句