此项目仅适用于 SwiftUI
当 View 使用 ignoresSafeArea 或 edgesIgnoringSafeArea(.bottom) 时
可以使用此框架,因为 TextField 和 TextEditor 无法使键盘弹起
封装了 UITextView, UITextField 也可以使用
@State private var text: String = ""
var body: some View {
VStack {
Spacer()
KeyboardHost {
TextField("please enter text", text: $text)
.frame(width: 200, height: 40, alignment: .center)
.padding(.bottom, 20)
}
}
.ignoresSafeArea()
}
您可以将 KeyboardHost 添加到 Xcode 项目,方法是将其添加为包依赖项。