mkto
mkto

Reputation: 4665

SwiftUI unable to restrict to landscape only

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:

enter image description here

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?

enter image description here

Upvotes: 8

Views: 3486

Answers (2)

Balwinder Singh Sohi
Balwinder Singh Sohi

Reputation: 69

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

Upvotes: 2

mkto
mkto

Reputation: 4665

enter image description here

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.

Upvotes: 16

Related Questions