我想要一個帶有 SwiftUI 的底部工具列。以下在 iOS 15 中有效,但在 iOS 16 中無效。在 iOS 16 中,工具列未顯示。(如果我改變位置,它會起作用......)
Text("Content")
.toolbar {
ToolbarItemGroup(placement: .bottomBar) {
Button("Greeting") {
print("Hello world!")
}
}
}
截圖
你有什么解決方法嗎?
謝謝!
uj5u.com熱心網友回復:
toolbar取決于導航欄,所以你必須有一個NavigationView/NavigationStack
https://developer.apple.com/documentation/swiftui/view/toolbar(content:)-5w0tj
struct ToolbarSolutionView: View {
var body: some View {
NavigationView{ //NavigationStack
Text("Content")
.toolbar {
ToolbarItemGroup(placement: .bottomBar) {
Button("Greeting") {
print("Hello world!")
}
}
}
}
}
}
這可能是它之前作業的錯誤。
如果不需要,可以隱藏導航欄。
//iOS 13
.navigationBarHidden(true)
//iOS 16
.toolbar(.hidden, for: .navigationBar)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/507540.html
上一篇:如何將資料從SwiftViewController傳遞到Obj-CViewController?
下一篇:來自Swift的等效目標C
