提问人:Ariel Antonio Fundora 提问时间:10/5/2023 最后编辑:Ariel Antonio Fundora 更新时间:10/19/2023 访问量:400
在 iOS 17 中将工具栏放在键盘上方不起作用
Placing the toolbar above keyboard does not work in iOS 17
问:
下一个代码片段是该问题的一个示例。
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 有什么解决方案吗?
答:
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 模拟器。这当然是一个错误。
评论