In SwiftUI iOS 14 why doesn't the TextEditor control automatically scroll up to avoid the keyboard as the TextField does?
Asked Answered
S

0

18

In iOS 14 the TextField automatically scrolls up when selected to avoid the keyboard but I can't get the same to happen for the new TextEditor control.

I have tried the following but it doesn't have any effect:

Form { Section(header: Text("Section Header")) {
  Spacer()
  TextEditor(text: $myComments).frame(height: 100).ignoresSafeArea(.keyboard, edges: .bottom)  } 
}
Spithead answered 5/12, 2020 at 13:35 Comment(7)
Works fine with Xcode 12.1 / iOS 14.1. Do you have other code around? Would you provide more context?Indoiranian
I am using Xcode 12.2 on iOS 14.2 - have also updated the code slightly to show the context.Spithead
Any luck resolving this? I have the same problem in Xcode 12.4/iOS 14.4.2?Vituperate
Same problem for iOS 15 / Xcode 13.1 Is there a way to adopt keyboard avoidance for TextEditor?Auditor
I didn't manage to resolve the original problem so I decided to create a navigation link with a destination page that contains just the TextEditor control. This then gives plenty of room for the keyboard without having to push the text editor up. Navigating back to the parent view will then just show a text box of the content that was entered. This approach is similar to how it works in the iOS Settings page where you change the name of your phone: Settings | General | About | Name - but instead of using just a Text field I use the TextEditor field.Spithead
Possible solution is here: https://mcmap.net/q/742618/-texteditor-is-obscured-by-keyboard-in-swiftuiIndoiranian
Aren't you ignoring the keyboard's safe area?Truitt

© 2022 - 2024 — McMap. All rights reserved.