在 iOS 17 中将工具栏放在键盘上方不起作用

Placing the toolbar above keyboard does not work in iOS 17

提问人:Ariel Antonio Fundora 提问时间:10/5/2023 最后编辑:Ariel Antonio Fundora 更新时间:10/19/2023 访问量:400

问:

下一个代码片段是该问题的一个示例。

import SwiftUI

struct TestingView: View {

  @State var myText = ""
  @State var myText2 = ""

  var body: some View {
     NavigationStack {
        Form {
            Text("Row 1")
            Text("Row 2")
            TextField("Write here", text: $myText)
            TextField("Write here too", text: $myText2)
        }
        .navigationTitle("Testing Toolbar") // delete if you want no title
        .navigationBarTitleDisplayMode(.inline)
        .toolbar {
            ToolbarItemGroup(placement: .keyboard) {
                Button {
                    print("Button up pressed")
                } label: {
                    Image(systemName: "chevron.up")
                }

                Button {
                    print("Button down pressed")
                } label: {
                    Image(systemName: "chevron.down")
                }
                Spacer()
            }
        }
    }

  }
 } 

struct TestingView_Previews: PreviewProvider {
   static var previews: some View {
      TestingView()
   } 
}

enter image description here

它在 iOS 16.4 或更低版本上运行良好,但在 iOS 17 上运行不正常。iOS 17 有什么解决方案吗?

iOS Swift SwiftUI 工具栏 iOS17

评论

0赞 workingdog support Ukraine 10/7/2023
在 iPhone (ios-17) 上对我有用,但我第一次打开应用程序时工具栏在 iPad (iPadOS-17) 上没有显示。但是,在 iPad 上关闭应用程序,然后再次选择它,将显示带有“V 形”的工具栏。在 MacOS 14.1、Xcode 15.1 上,在真实设备上测试(非预览版)。
0赞 Josh Brown 10/11/2023
我也在运行 iOS 13 的 iPhone 17.0.3 Pro 上看到了这一点。
0赞 Sebastian 10/11/2023
我在 iPhone 13 Pro 上遇到了同样的问题(适用于 iOS16.4,但到目前为止适用于 iOS 17)。
0赞 HeGe 10/13/2023
在Apple论坛上看到了一些关于此问题的帖子,但尚未:(解决方案
0赞 Sebastian 10/19/2023
你能提供一个链接吗?

答:

0赞 Sebastian 10/19/2023 #1

找到了解决方法:向 NavigationStack 添加一个空的导航路径为我解决了这个问题(到目前为止)。

@State var path = NavigationPath()

NavigationStack(path: $path) {
...
}

学分:https://stackoverflow.com/a/75756609/10603205

0赞 JAHelia 11/29/2023 #2

它适用于 iOS 17+ 设备和 16.0+ 设备和模拟器,但不适用于 iOS 17 模拟器。这当然是一个错误。