【发布时间】:2021-08-18 02:35:59
【问题描述】:
长话短说,这是用户通过身份验证后的入职视图。我的应用程序的主要导航使用navigationview,但我不能将其用于入职。我已经在主屏幕上放了一个全屏封面来显示这些入门内容。
但是,当尝试在入门屏幕之间的不同文件的视图之间简单导航时,该按钮不会显示其他视图。我已经尝试了@Appstorage 和@Environment 的所有东西,但无法让它工作。
另外请注意,我切断了文件其余部分的底部,因为这与此逻辑无关。
import SwiftUI
struct OnboardingTestView: View {
@State var shouldShowOnboarding = true
var body: some View {
if shouldShowOnboarding {
OffsetChoicesView(shouldShowOnboarding: $shouldShowOnboarding)
}
if shouldShowOnboarding == false {
PersonalInfoView()
}
}
}
struct OnboardingTestView_Previews: PreviewProvider {
static var previews: some View {
OnboardingTestView()
}
}
//*********************************************************************
//OffsetChoicesView
struct OffsetChoicesView: View {
@Binding var shouldShowOnboarding: Bool
var body: some View {
ZStack {
Color(#colorLiteral(red: 0.9803921569, green: 0.9568627451, blue: 0.9568627451, alpha: 1)).edgesIgnoringSafeArea(/*@START_MENU_TOKEN@*/.all/*@END_MENU_TOKEN@*/)
VStack {
Progress1View()
.padding(.bottom, 40)
.padding(.top)
Spacer()
Button(action: {
shouldShowOnboarding = false
}) {
NextButtonView()
.padding(.top)
.padding(.bottom)
}
}
【问题讨论】:
-
代替
if shouldShowOnboarding == false {试试else { -
另外,尝试将 if 语句嵌入到
VStack或Group -
此代码在
NextButtonView按钮上向我显示PersonalInfoView。 p.s.即使您使用的是fullScreenCover,您也可以在其中再声明一个NavigationView,然后毫无问题地使用NavigationLink
标签: swiftui swiftui-environment