[英]SwiftUI: How do I display a view as a pop up on top of the current view blurred in the background?
[英]In SwiftUI, how do I remove a view stuck on top of the keyboard
我在表单下有一个视图。 当我输入文本字段时,视图卡在键盘顶部。
有问题的代码:
// other stuff
Form {
Section {
TextField("Enter your desired username", text: $page.username)
}
Section {
Button(action: createUser) {
Label("Sign Up", systemImage: "person.crop.circle.badge.plus")
}
}
}
// this is getting stuck on top of keyboard
Group {
Text("By signing up you agree to")
// other stuff
}
它看起来像什么:
如您所见,“通过注册...”视图卡在键盘顶部。 我怀疑它与菜单有关。
我该如何摆脱它?
您是否在其他容器(如 VStack)中有表单和组? 我认为您必须……如果是这样,解决方案是将.ignoresSafeArea(.keyboard, edges: .bottom)
添加到该容器中。
例如,
VStack {
Form {
...
}
Group {
...
}
}
.ignoresSafeArea(.keyboard, edges: .bottom)
对 Group 应用ignoresSafeArea
不起作用,因为它的容器(这里是 VStack)仍然可以通过键盘调整大小。 如果在容器中添加ignoresSafeArea
会产生不良后果,请发布更多代码,以便我们了解情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.