I have created a simple debug app using Swift/SwiftUI to understand this issue I have seen in my app. The debug app is just a VStack with .border(Color.red). It has text in the upper left, upper right, and bottom so the red rectangle goes around the entire screen. This is done just using VStack{}, HStack{}, Text(), and Spacer().
I have my debug app running and then bring up another app (gmail, google keep, and duck-duck-go browser all work). I open the keyboard in this other app. I swipe my finger from left to right on the bottom of the screen to go back to my app. When it first opens it looks correct but within a second or two the bottom of the red rectangle and the word on the bottom of my debug app move up about where they would be if there was a keyboard, but there is no keyboard.
Some findings:
- Rotating the iPad does not fix the issue.
- With stage manager off this doesn't happen.
- Adding "sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)" to a UIApplication extension and calling that doesn't fix it.
- Adding a TextField() and touching that to bring up the keyboard and then calling the UIApplication extension does fix it.
- Going to another app and back fixes it assuming the other app doesn't have the keyboard open.
- Not all applications with the keyboard open will cause this issue.
- Issue happens in landscape and portrait rotation
- If I add a GeometryReader and add Text() to show it and the UIScreen.main.bounds, the bounds don't change with/without issue but geometry does
My system:
- 11in M1 iPad pro running 16.6.1. 512GB with Stage Manager on
- Xcode 14.3.1
Other apps don't have this issue so what am I missing? Thanks for any help.
The debug app:
struct ContentView: View {
var body: some View {
VStack {
HStack {
Text("Top")
Spacer()
Text("Top")
}
Spacer()
Text("Bottom")
}.border(Color.red)
}
}
...Gary