[英]Toolbar bottom iOS 16 - SwiftUI
我想要一个带有 SwiftUI 的底部工具栏。以下在 iOS 15 中有效,但在 iOS 16 中无效。在 iOS 16 中,工具栏未显示。 (如果我改变位置,它会起作用......)
Text("Content")
.toolbar {
ToolbarItemGroup(placement: .bottomBar) {
Button("Greeting") {
print("Hello world!")
}
}
}
你有什么解决方法吗?
谢谢!
我遇到了同样的问题。 更新到iOS 16.1后解决。
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)
对我来说,任何有条件bottomBar
都不会显示,即使 iOS 16 上的showTB == true
也是如此。
.toolbar {
ToolbarItem(placement: .bottomBar) {
if showTB {
Button("Delete") {
print(234)
}
}
}
}
在 iOS 16.1 Beta 上进行测试,它似乎已针对 iOS 16.1 修复。
无论我做什么,我都无法让 ToolbarItemGroup 在 iOS 16.1.1 中使用.bottomBar修饰符,它在 iOS 15.4 中工作正常。
父视图有 NavigationView,下面的嵌套视图(四层;顶层、子层 1/2/3)各有不同的工具栏菜单。
对于 iOS16.1.1,如果我 go 到 sublevel 2 并返回到顶部,然后返回到 sublevel 1,则会出现 sublevel 1 工具栏(但似乎是双层)。 子级别 2/3 不工作。
所以以下不适用于 16.1(适用于 15.4)
.toolbar {
ToolbarItemGroup(placement: .bottomBar) {
ToolBarMenu(bgxDevice: bgxDevice)
.font(.caption)
}
}
但是.automatic下面的作品..(但不正确,因为有很多按钮)
.toolbar {
ToolbarItemGroup(placement: .automatic) {
ToolBarMenu(bgxDevice: bgxDevice)
.font(.caption)
}
}
任何想法如何让修饰符.bottomBar工作? 这是iOS16.1.1的错误吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.