I’m trying to get the keyboard to respect the TextField
when it’s brought up. I understand that in iOS 14.2+, this is the default behavior. However, in my testing, I noticed 2 things:
- The keyboard’s
inputAccessoryView
is still not taken into account. i.e. if the keyboard has ainputAccessoryView
, it can still cover up theTextField
. See the 1st screenshot I attached. - There’s not enough padding between the keyboard and the
TextField
. See the 2nd screenshot. i.e. I’m. trying to achieve the effect mentioned in this post.
Here’s the code I used for testing:
struct CommentView: View {
@State var text = ""
@FocusState private var isFocused: Bool
var body: some View {
VStack {
Spacer()
Image(uiImage: UIImage(named: "dog.jpeg")!)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 350, height: 500)
.overlay(alignment: .center) {
VStack {
Spacer()
TextField("Add a comment", text: $text, axis: .vertical)
.multilineTextAlignment(.leading)
.foregroundColor(.white)
.keyboardType(.alphabet)
// .disableAutocorrection(true) // A hack to disable the inputAccessoryView
.submitLabel(.done)
.padding([.top, .bottom], 8)
.padding([.horizontal], 16)
.background(Color.black.opacity(0.7))
}
}
.clipShape(RoundedRectangle(cornerRadius: 20))
}
}
}
inputAccessoryView
covering the TextField
:
Not enough padding between keyboard and TextField
:
Does anyone know how to fix this?