-1

长话短说,这是用户通过身份验证后的入职视图。我的应用程序主导航使用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)
                }
            
            }
4

1 回答 1

0

你可以尝试这样的事情 - 利用@AppStorage

我不太确定OffsetChoiceView()参数应该是什么......所以我只是在示例中删除了它们。这应该是您的入职视图。

    import SwiftUI

struct OnboardingTestView: View {
    //@State var shouldShowOnboarding = true
    
    @AppStorage("showOnboarding") var showOnboarding: Bool = true
    var body: some View {
        if (showOnboarding == true) {
            OffsetChoicesView()
        } else if (showOnboarding == false) {
            PersonalInfoView()
        }
    }
}

struct OnboardingTestView_Previews: PreviewProvider {
    static var previews: some View {
        OnboardingTestView()
    }
}

//*********************************************************************
//OffsetChoicesView

struct OffsetChoicesView: View {
    //@Binding var shouldShowOnboarding: Bool
    @AppStorage("showOnboarding") var showOnboarding: Bool = false
    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: {
                    showOnboarding = false
                }) {
                    NextButtonView()
                        .padding(.top)
                        .padding(.bottom)
                }
            
            }
于 2021-08-18T02:51:54.387 回答