How to show complete List when keyboard is showing up in SwiftUI

前端 未结 7 571
广开言路
广开言路 2020-12-04 22:30

How is it possible to show the complete List when the keyboard is showing up? The keyboard is hiding the lower part of the list.

I have a textField in my list row. W

7条回答
  •  [愿得一人]
    2020-12-04 23:11

    One Line Solution with SwiftUIX

    If you install SwiftUIX, all you need to do is called, .padding(.keyboard) on the View that contains the list. This is by far the best and simplest solution I have seen!

    import SwiftUIX
    
    struct ExampleView: View {
        var body: some View {
            VStack {
               List {
                ForEach(contacts, id: \.self) { contact in
                    cellWithContact(contact)
                }
               }
            }.padding(.keyboard) // This is all that's needed, super cool!
        }
    }
    

提交回复
热议问题