在 iOS16 中,工作表内部存在键盘的错误,当工作表关闭时键盘消失(没关系),但布局未更新。我只看到了关于同一问题的 1 个问题,想知道也许有人找到了临时解决方法,直到苹果不解决这个问题。
重现代码:
struct Test: View {
@State var isPresented: Bool = false
@State var text: String = ""
var body: some View {
VStack{
Button {
isPresented.toggle()
} label: {
Text("PRESENT")
}
}
.sheet(isPresented: $isPresented) {
ZStack {
Color.red
VStack{
TextField("Test", text: $text)
.frame(height: 50, alignment: .center)
Spacer()
Rectangle()
.fill(Color.blue)
.frame(width:300, height: 50)
}
}
}
}
}
Video:
https://vimeo.com/758845068
The .ignoresSafeArea()
解决了问题,但是...
这将由于 UI 中的键盘重叠而导致无法滚动查看所有元素。
我用.adaptsToKeyboard()
自定义修饰符取自此answer
然后在需要的地方按照这个特定的顺序使用它。
VStack {...}
.adaptsToKeyboard()
.ignoresSafeArea()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)