我是 swiftui 和編程的新手,所以如果我沒有使用正確的語言,請原諒。
我的問題是,一旦我的應用程式啟動,它就會顯示一個非常奇怪的視圖,頂部有一個導航欄和一個空白螢屏。我必須來回滑動幾次才能使應用程式按預期運行。這是問題的視頻。
因此,在我的內容視圖檔案中,我有一個標簽欄,其中包含對我的其他 2 個視圖的參考。
TabView{
SearchPageView()
.tabItem {
Image(systemName: "magnifyingglass")
.font(.system(size: 25, weight: .bold))
}
MainPageView()
.tabItem {
Image(systemName: "house")
}
}.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
.ignoresSafeArea()
我為我的每個視圖創建了一個單獨的檔案。這兩個視圖都包含在 naviagtionView 中,稍后我將使用導航鏈接導航到單獨的視圖。除了滾輪的型別不同,兩頁的寫法完全相同,一個是水平的,另一個是垂直的。
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)
}
任何幫助表示贊賞。提前致謝。
uj5u.com熱心網友回復:
您應該洗掉.tabViewStyleContentView中的修飾符。
TabView在 SwiftUI 中有兩個截然不同的角色。一種是管理一個標簽欄,它允許您點擊標簽欄中的圖示來選擇要顯示的視圖;另一種方法是提供可滑動的分頁視圖集合。
鑒于您NavigationView在子視圖中的使用,我會說第一種樣式是您想要的樣式。這是默認設定,因此洗掉樣式修飾符(將選項卡視圖切換到第二種形式),一切都應該很好。您還應該能夠洗掉.ignoresSafeArea修飾符。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/382346.html
上一篇:Xcode13.2包問題
