1

How Can I hide NavigationBar.

it works in this way respectively: 1- OnboardingView 2- MainView 3- LoginView 4- StepView

I don't want the NavigationBar on the StepView screen. I couldn't hide the NavigationBar with the code below.

I shared the screenshot below with you.

struct StepView: View { var body: some View { VStack { Text("Hello, World!") } .navigationTitle("") .navigationBarBackButtonHidden(true) .navigationBarHidden(true) } } 

OnboardingView

struct OnboardingView: View { @State var currentPageIndex = 0 @State var next: Bool = false let timer = Timer.publish(every: 2, on: .main, in: .common).autoconnect() var subviews = [ UIHostingController(rootView: SubView(imageString: "OnboardingImageOne")), UIHostingController(rootView: SubView(imageString: "OnboardingImageOne")), UIHostingController(rootView: SubView(imageString: "OnboardingImageOne")) ] var titles = ["Take some time out", "Conquer personal hindrances", "Create a peaceful mind"] var captions = ["Take your time out and bring awareness into your everyday life", "Meditating helps you dealing with anxiety and other psychic problems", "Regular medidation sessions creates a peaceful inner mind"] let coloredNavAppearance = UINavigationBarAppearance() init() { coloredNavAppearance.configureWithOpaqueBackground() coloredNavAppearance.backgroundColor = .clear coloredNavAppearance.titleTextAttributes = [.foregroundColor: UIColor.white] coloredNavAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white] UINavigationBar.appearance().standardAppearance = coloredNavAppearance UINavigationBar.appearance().scrollEdgeAppearance = coloredNavAppearance } var body: some View { NavigationView { VStack { ... VStack { PageControl(numberOfPages: subviews.count, currentPageIndex: $currentPageIndex) NavigationLink(destination: MainView(), isActive: $next) { Button(action: { self.next = true self.timer.upstream.connect().cancel() }) { Text("Devam Et") .foregroundColor(.black) .padding(.vertical,25) .padding(.horizontal,UIScreen.main.bounds.width / 3) } .background(Color("ColorWelcome")) .clipShape(Capsule()) } } } .background(Color("ColorOnboarding").edgesIgnoringSafeArea(.all)) .navigationBarTitle("", displayMode: .inline) .navigationBarItems(leading: HStack { Text("Walker") Image("logo") Text("App") } .frame(width: UIScreen.main.bounds.width, alignment: .center) ) ... } .navigationViewStyle(StackNavigationViewStyle()) } } 

MainView

struct MainView: View { @State var loginView: Bool = false var body: some View { ZStack{ Image("Welcomebg") .frame(height: UIScreen.main.bounds.height, alignment: .top) VStack { Spacer() Image("WelcomeImage") Text("Description") Spacer() NavigationLink(destination: LoginView(), isActive: $loginView) { Button(action: { self.loginView = true }) { Text("GİRİŞ YAP") .foregroundColor(.white) .padding(.vertical,25) .padding(.horizontal,UIScreen.main.bounds.width / 3) .font(Font.custom("SFCompactDisplay-Bold", size: 14)) } .background(Color("ColorOnboarding")) .clipShape(Capsule()) .padding(.top,20) } ... } } 

LoginView

 struct LoginView: View { ZStack { ... NavigationLink( destination: StepView(), isActive: $isOpenStepView, label: { Button(action: { if emailAddress.count > 6 { self.isLoginSuccess = true self.showingAlert = true DispatchQueue.main.asyncAfter(deadline: .now() + 2) { self.isOpenStepView = true } } else { self.isLoginSuccess = false self.showingAlert = true } }) { Text("GİRİŞ YAP") .foregroundColor(.white) .padding(.vertical,25) .padding(.horizontal,UIScreen.main.bounds.width / 3) .font(Font.custom("SFCompactDisplay-Bold", size: 14)) } .background(Color("ColorOnboarding")) .clipShape(Capsule()) .padding(.top,20) }) ... } } 

StepView:

struct StepView: View { var body: some View { VStack { Text("Hello, World!") } .navigationTitle("") .navigationBarBackButtonHidden(true) .navigationBarHidden(true) } } 

Screen shoot

5
  • Does this answer your question stackoverflow.com/a/62657005/12299030? Commented Nov 19, 2020 at 16:45
  • This works, but I didn't want to use environmentobject. Commented Nov 19, 2020 at 16:50
  • 1
    How did you pass it does not really matter (almost) - the root of solution is that you need to hide it via dynamic property in first screen containing NavigationView. Commented Nov 19, 2020 at 17:21
  • @Asperi thank you sir. I solved. Commented Nov 19, 2020 at 17:31
  • Does this answer your question? Navigation Bar hide is not working in SwiftUI Commented Feb 12, 2021 at 21:57

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.