![](/img/trans.png)
[英]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.