【问题标题】:SwiftUI - How to prevent keyboard in a sheet to push up my main UISwiftUI - 如何防止工作表中的键盘向上推我的主 UI
【发布时间】: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)
    }
}

【问题讨论】:

标签: ios swift xcode swiftui keyboard


【解决方案1】:

我曾经遇到过类似的问题。我无法重现您的代码,但您可以尝试像这样使用 GeometryRadar:

    GeometryReader { geometry in
        ZStack {
            VStack {
                
                // This is the part that moves up and down
            }
        }
    }
    .ignoresSafeArea(.keyboard, edges: .bottom)



        

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-11
    • 1970-01-01
    • 2022-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多