LAST CHANCE: Save 50% on all my Swift books and bundles! >>

iOS 16 TextField, axis parameter, and keyboard avoidance

Forums > SwiftUI

I've not seen the issue I'm having discussed here or anywhere else since iOS 16 dropped. I've added the axis: .vertical parameter to a TextField view to make it expand vertically, eliminating the need for a ZStack hack that accomplished the same previously. The automatic keyboard avoidance behavior that was working as-expected prior to adding the new parameter has ceased. When I tap in the TextField now, the keyboard jumps up and covers it.

Has anyone else seen this?

Here's the code snippet in question:

                    TextField("", text: $cocktail.userNotes, axis: .vertical)
                       .placeHolder(Text("My notes"), show: cocktail.userNotes.isEmpty)
                       .padding(.vertical, 6)
                       .background(RoundedRectangle(cornerRadius: 4)
                                        lineWidth: Constants.size.editBorderWidth))


I'm having the same issue and I didn't yet find any suitable solution...


Having the same issue. What was your solution with a ZStack?


I have the same issue with a TextEditor ...

I'm guessing this will work for both TextEditor and TextField with axis parameter:

But I don't want to implement this just for just one TextEditor ... 🤨


This solution worked for me when I had a TextField with axis vertical added. This site won't let me post the link that has the write up.

But here is the code example:

List(messages) { message in
.safeAreaInset(edge: .bottom) {
        "New message",
        text: $newMessageText
        .onSubmit {
            // append message

Put the TextField as a view in safeArea inset. Works great.


Hacking with Swift is sponsored by Essential Developer.

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until July 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.