Consider the following sample code
Code is pretty straightforward and is the proposed way for SwiftUI's dynamic interfaces. IE: you double down on your elements, and the interface gets switched from one to the other.
Now this piece of code, compared to the one without the if portrait has multiple issues because of the keyboard.
Code Block swift import SwiftUI struct ContentView: View { @State var text = "" @State var portrait = true func updateInterfaceOrientation() { guard let currentWindowScene = UIApplication.shared.connectedScenes.first( where: { $0.activationState == .foregroundActive }) as? UIWindowScene else { return } self.portrait = currentWindowScene.interfaceOrientation.isPortrait } var body: some View { ZStack { if portrait { VStack { Spacer() TextField("", text: $text) .background(Color.gray) } } else { VStack { Spacer() TextField("", text: $text) .background(Color.gray) } } } .onAppear(perform: updateInterfaceOrientation) .onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in updateInterfaceOrientation() } } }
Code is pretty straightforward and is the proposed way for SwiftUI's dynamic interfaces. IE: you double down on your elements, and the interface gets switched from one to the other.
Now this piece of code, compared to the one without the if portrait has multiple issues because of the keyboard.
When the portrait vs landscape gets changed, you lose the on-screen keyboard. I can kind-of live with that.
iOS 14: When you have a on-screen keyboard in portrait mode, and you move to landscape mode, the zone stays higher on screen, as if the keyboard was actually there, but it's not. If you move back to portrait mode, the safe zone becomes 3/4 of the screen. I cannot live with that!