简体   繁体   English

工具栏底部 iOS 16 - SwiftUI

[英]Toolbar bottom iOS 16 - SwiftUI

I would like to have a bottom toolbar with SwiftUI. The following is working in iOS 15, but not in iOS 16. In iOS 16 the toolbar is not showing.我想要一个带有 SwiftUI 的底部工具栏。以下在 iOS 15 中有效,但在 iOS 16 中无效。在 iOS 16 中,工具栏未显示。 (It's working if I change the placement...) (如果我改变位置,它会起作用......)

Text("Content")
    .toolbar {
        ToolbarItemGroup(placement: .bottomBar) {
            Button("Greeting") { 
                print("Hello world!")
            }
        }
    }

Screenshots截图

Do you have any workaround for this?你有什么解决方法吗?

Thanks!谢谢!

I got the same issue.我遇到了同样的问题。 It is resolved after updating to iOS 16.1.更新到iOS 16.1后解决。

toolbar depends on the navigation bar so you have to have a NavigationView / NavigationStack toolbar取决于导航栏,所以你必须有一个NavigationView / NavigationStack

https://developer.apple.com/documentation/swiftui/view/toolbar(content:)-5w0tj 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!")
                        }
                    }
                }
        }
    }
}

It was likely a bug that it was working before.这可能是它之前工作的错误。

You can hide the navigation bar if you don't need it.如果不需要,可以隐藏导航栏。

//iOS 13+
.navigationBarHidden(true)

//iOS 16+
.toolbar(.hidden, for: .navigationBar)

For me, any conditional bottomBar does not get displayed at all, even if showTB == true on iOS 16.对我来说,任何有条件bottomBar都不会显示,即使 iOS 16 上的showTB == true也是如此。

  .toolbar {
    ToolbarItem(placement: .bottomBar) {
      if showTB {
        Button("Delete") {
          print(234)
        }
      }
    }
  }

Testing on the iOS 16.1 Beta, it seems to be fixed for iOS 16.1 though.在 iOS 16.1 Beta 上进行测试,它似乎已针对 iOS 16.1 修复。

Whatever I do I cannot get the ToolbarItemGroup to work with .bottomBar modifier in iOS 16.1.1 It works fine with iOS 15.4.无论我做什么,我都无法让 ToolbarItemGroup 在 iOS 16.1.1 中使用.bottomBar修饰符,它在 iOS 15.4 中工作正常。

The parent View has NavigationView and the nested views (four levels; top,sublevel 1/2/3) underneath have each different ToolBar menus.父视图有 NavigationView,下面的嵌套视图(四层;顶层、子层 1/2/3)各有不同的工具栏菜单。

With iOS16.1.1 if I go to sublevel 2 and return back to top and then back to sublevel 1, the sublevel 1 toolbar appears (but there seems to be double layer).对于 iOS16.1.1,如果我 go 到 sublevel 2 并返回到顶部,然后返回到 sublevel 1,则会出现 sublevel 1 工具栏(但似乎是双层)。 Sublevels 2/3 not working.子级别 2/3 不工作。

So the below does not work on 16.1 (works on 15.4)所以以下不适用于 16.1(适用于 15.4)

    .toolbar {
        ToolbarItemGroup(placement: .bottomBar) {
            ToolBarMenu(bgxDevice: bgxDevice)
                .font(.caption)
        }
    }

But .automatic below works.. (but not right as have many buttons)但是.automatic下面的作品..(但不正确,因为有很多按钮)

 .toolbar {
            ToolbarItemGroup(placement: .automatic) {
                ToolBarMenu(bgxDevice: bgxDevice)
                    .font(.caption)
            }
        }

Any ideas how to get modifier .bottomBar to work?任何想法如何让修饰符.bottomBar工作? Is this bug with iOS16.1.1?这是iOS16.1.1的错误吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM