[英]SwiftUI - Empty bottom bar after tapping NavigationLink
我有一個帶有toolbar
的NavigationView
,其中包含一個帶有ToolBarItem
位置的.bottomBar
和一個搜索字段。 這個NavigationView
包含一個ScrollView
,其內容超出了屏幕的垂直尺寸,這意味着底部欄有背景,如下所示:
當用戶點擊“Root View”文本元素時,他們導航到一個新視圖,在本例中,只是另一個顯示“Detail View”的文本。 然而,問題是底部工具欄的背景保留在屏幕中,而不是像預期的那樣消失。 請參見下面的屏幕截圖:
如果我刪除搜索欄或縮小ScrollView
的高度以適合設備的垂直尺寸,則不會看到此行為。 我試着用谷歌搜索這個問題,看看它是否是一個有解決方法的已知錯誤,但也許我沒有搜索正確的關鍵字。 我該如何解決這個問題?
請查看最低限度以復制以下問題:
struct BugView: View {
@State var searchPattern: String = ""
var body: some View {
NavigationView {
ScrollView {
VStack {
NavigationLink(destination: Text("Detail View")) {
Text("Root View").foregroundColor(Color.blue)
}
Spacer()
Text("Root View Bottom").foregroundColor(Color.blue)
}.frame(maxWidth: .infinity, minHeight: 1000)
}
.searchable(text: self.$searchPattern, prompt: "Search Here")
.toolbar(content: {
ToolbarItem(placement: .bottomBar) {
Text("Toolbar text")
}
})
}
}
}
設置:
您可以使用 the.toolbar(.hidden, for: .bottomBar) 作為目標視圖,如下面的代碼所示:
struct ContentView: View {
var body: some View {
NavigationView {
NavigationLink {
Text("Destination View")
} label: {
// hiding the toolbar for the destination view
Text("Root View").toolbar(.hidden, for: .bottomBar)
}
}.toolbar {
ToolbarItem(placement: .bottomBar) {
Text("Toolbar Text")
.background {
Color.gray
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.