在iOS 17中,将工具栏放在键盘上方无法正常工作。

4
下面的代码片段是一个问题的示例。
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的解决方案?

在我的iPhone(iOS-17)上运行正常,但在iPad(iPadOS-17)上第一次打开应用时工具栏不显示。 然而,在iPad上关闭应用,然后再次选择它,工具栏会显示出可用的“chevrons”。 在MacOS 14.1,Xcode 15.1上测试了真实设备(非预览)。 - undefined
我也遇到了这个问题,在运行iOS 17.0.3的iPhone 13 Pro上。 - undefined
我在我的iPhone 13 Pro上遇到了同样的问题(在iOS 16.4上工作,但在iOS 17上出现了问题)。 - undefined
在苹果论坛上看到了一些关于这个问题的帖子,但还没有解决办法 :( - undefined
你能提供一个链接吗? - undefined
iOS 17.1仍然存在问题 :-/ - undefined
2个回答

0
它适用于iOS 17+设备和16.0+设备以及模拟器,但不适用于iOS 17模拟器。这肯定是一个错误。

0
找到了一个解决办法:在导航栈中添加一个空的导航路径解决了我的问题(至今为止)。
@State var path = NavigationPath()

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

致谢:https://stackoverflow.com/a/75756609/10603205

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接