首页 > 解决方案 > 出现键盘时,带有部分 Texteditor 的 SwiftUI 表单向上移动

问题描述

我有一个问题,在 Stack 上阅读了很多解决方案,但没有任何效果。我有一个包含不同部分、TextFields 和最后一个 Texteditor 的表单视图。当我单击文本编辑器时,表单中的编辑器应该在键盘上方。

我的代码:

var body: some View {
        NavigationView{
            VStack{
            Form{
                Section{TextField}
                Section{TextField}
             
                Section{
                    ZStack{
                        TextEditor
                    }
                }
                Section{
                    ZStack{
                    TextEditor(text: $info)
                        .ignoresSafeArea(.keyboard)
                    Text(info).opacity(0).padding(.all, 8)
                    }
                }
            }
            .frame(alignment: .top)
            .navigationBarItems(leading: Button(action: {
                self.addUser = false
                
            }, label: {
                Image(systemName: "chevron.backward")
            }))
        }.onTapGesture {
            UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
        }
       }.navigationBarTitle("Kunden Hinzufügen", displayMode: .inline)
}
}

在此处输入图像描述

标签: swiftuitextfield

解决方案


推荐阅读