I am trying to build a landscape-only app in Xcode 13 and SwiftUI. I notice even if I have unchecked "Portrait" orientation, the app will still work in portrait mode. I am unable to force the app to work in landscape mode.
This is the Device Orientation Settings:
This is the simple hello world SwiftUI:
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello, world!")
.padding()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Expected:
"Hello world" rotated 90degree clockwise when device in portrait mode. Forcing user to rotate the device to landscape mode to view correctly.
Actual:
"Hello world" still renders correctly in portrait mode. Why?
2
Answers
Turns out there is still some portrait and landscape orientations defined in the "Build Settings" tab. Once the portrait orientations deleted here, it works as expected.
Go it the main and select TARGETS then select the Info tab (the plist) and open Supported interface orientations (iPhone) then click on the ones that you do not need. Just leave Portrait(bottom home button). delete Other, This Should solve your issue