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)
}
}