I am new to swiftui and programming in general so please excuse me if I am not using the proper language.
My problem is that as soon as my app starts, it shows a very weird view with a navigation bar at the top and a blank screen. I have to swipe back and forth a couple of times to get the app to function as expected. Here is the Video of the problem.
So in my Content View file I have a tab Bar with references to my other 2 views.
TabView{
SearchPageView()
.tabItem {
Image(systemName: "magnifyingglass")
.font(.system(size: 25, weight: .bold))
}
MainPageView()
.tabItem {
Image(systemName: "house")
}
}.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
.ignoresSafeArea()
I have created a separate file for each of my views. Both of the views are wrapped in a naviagtionView as later on I use the navigation link to navigate to a separate view. Both of the pages are written exactly the same except for the type of scroll wheel, one is a horizontal while the other is a vertical.
NavigationView{
VStack{
Spacer()
Text("Friends")
.foregroundColor(.white)
.font(.largeTitle)
.fontWeight(.bold)
ScrollView(.horizontal,showsIndicators: false){
HStack{
ForEach(users){ users in
NavigationLink(destination: UserDisplayPage(user: users).navigationTitle("")
.navigationBarHidden(true)
){
VStack(alignment: .center){
Image(users.imageName)
.resizable()
.aspectRatio( contentMode: .fill)
.frame(width: imageSize, height: imageSize
)
.cornerRadius(imageSize/2)
.overlay(
Circle().stroke(Color.white, lineWidth: 5)
)
.padding()
Text(users.name)
.font(.title)
.fontWeight(.bold)
.foregroundColor(.white)
}
}
}
}
}
Spacer()
}.background(
LinearGradient(colors: [.myPurple,.myCyan,.myOrange], startPoint: .topLeading, endPoint: .bottomLeading)
)
.navigationTitle("Good Evening, Nihal")
.foregroundColor(.myOrange)
}
Any help is appreciated. Thanks in advance.
CodePudding user response:
You should remove the .tabViewStyle
modifier in your ContentView.
TabView
has two very different roles in SwiftUI. One is to manage a tab bar which allows you to tap on icons in a tab bar to choose which view to display; another is to provide a swipeable, paged collection of views.
Given your use of NavigationView
within your sub views, I’d say the first style is the one you want. That’s the default, so remove the style modifier (which switches the tab view to the second form) and all should be well. You should also be able to remove the .ignoresSafeArea
modifier.