【发布时间】:2021-12-26 03:04:01
【问题描述】:
我在引导过程中使用工作表 (SwiftUI) 让人们输入文本,但是每当关闭工作表时,背景中的元素就会移动,就好像键盘在上下推动它们一样。如果键盘不在屏幕上,则在关闭工作表时背景中的元素不会移动。我尝试使用 .ignoresSafeArea(.keyboard, edges: .bottom) 但它似乎不起作用。
关于如何在关闭带有键盘的工作表时“修复”背景元素的任何想法?
private var welcomeSection5: some View {
ZStack {
VStack {
// This is the part that moves up and down
TellSlideView(text: "And what's your age \(userName) if I may?")
Spacer()
Button(action: {
displaySheet.toggle()
}, label: {
Text("Enter age")
.padding()
.foregroundColor(Color.white)
.frame(maxWidth: .infinity)
.background(Color.MyTheme.Purple)
.cornerRadius(15)
.padding(.horizontal)
.padding(.bottom, 40)
})
}.sheet(isPresented: $displaySheet) {
AddUserAgeView(onboardingState: $onboardingState)
}.ignoresSafeArea(.keyboard, edges: .bottom)
}
}
【问题讨论】:
-
欢迎来到 Stack Overflow!请拨打tour 并查看:How do I ask a good question? 和How to create a Minimal, Reproducible Example。没有 MRE,我们无法调试这个,但是this question 对这些问题进行了很好的讨论。
标签: ios swift xcode swiftui keyboard