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

hyrbngr7  于 12个月前  发布在  iOS
关注(0)|答案(1)|浏览(96)

下一个代码片段是这个问题的一个例子。

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()
   } 
}

它在iOS 16.4或更低版本上运行良好,但在iOS 17上不运行。iOS 17的解决方案?

w51jfk4q

w51jfk4q1#

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

@State var path = NavigationPath()

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

来源:https://stackoverflow.com/a/75756609/10603205

相关问题