我有一个关于迅速的问题。如何导航到视图?
现在,我的ContentView在有条件的(if)中显示launchScreen,Login或HomeView。
var body: some View {
VStack {
if (sessionStore.session != nil) {
UserProfileView(userProfile: self.profile ?? UserProfile(uid: "", firstName: "", lastName: "", birth: "", email: "", phone: ""))
} else if show || UserDefaults.standard.bool(forKey: initialLaunchKey){
AuthentificationView().transition(.move(edge: .bottom))
} else {
PageViewContainer( viewControllers: Page.getAll.map({ UIHostingController(rootView: PageView(page: $0) ) }), presentSignupView: { withAnimation { self.show = true }; UserDefaults.standard.set(true, forKey: self.initialLaunchKey) }).transition(.scale)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.backgroundColor)
.onTapGesture { UIApplication.shared.endEditing() }
}
但是,如果我在LoginView中,即使我在ContentView for HomeView中的情况变为真,我也不会进入HomeView ...
我通过可观察对象中的var进入视图(页面= 1,然后页面= 2 ...),我认为这不是更好的方法...
struct AuthentificationView: View {
@EnvironmentObject var userSignup: UserSignup
var body: some View {
VStack {
if (userSignup.page >= 1) {
SignupView()
.transition(.asymmetric(insertion: .move(edge: .trailing), removal: .move(edge: .leading)))
} else {
LoginView()
.transition(.asymmetric(insertion: .move(edge: .leading), removal: .move(edge: .trailing)))
}
}
}
}
谢谢
答案 0 :(得分:0)
我无法测试您的代码(由于缺少自定义功能),因此仅凭经验尝试以下操作
像下面一样(抓痒)
var body: some View {
VStack {
if userSignup.page >= 1 {
SignupView()
.transition(AnyTransition.asymmetric(insertion: .move(edge: .trailing),
removal: .move(edge: .leading)).animation(.default))
}
if userSignup.page == 0 {
LoginView()
.transition(AnyTransition.asymmetric(insertion: .move(edge: .leading),
removal: .move(edge: .trailing)).animation(.default))
}
}.animation(.default)
}