Short answer

To keep an iPhone app in portrait, untick the landscape boxes under Deployment Info in your target, or list only UIInterfaceOrientationPortrait in UISupportedInterfaceOrientations. To lock one screen, override supportedInterfaceOrientations in that view controller and make your navigation or tab bar controller pass the question on. On iPad it works differently: from iPadOS 26 an app that supports multitasking has to handle every orientation, and the old opt-out, UIRequiresFullScreen, is deprecated.

SWIFT TIPS · UIKIT

First posted on April 4, 2018 for Swift 4 and Xcode 9, under the title "Disble Auto Layout Swift 4". Rewritten on November 17, 2026. The Swift code below was type-checked on a Mac with Xcode 26.2 against the iOS 26.2 SDK, in Swift 5 and Swift 6 language modes, with iOS 15 as the deployment target. It wasn't run on a device.

The 2018 version of this post had the wrong title. It said Auto Layout, but the problem I was solving was rotation: my app turned sideways when the phone did, and the layout wasn't built for it. I found the fix on Stack Overflow, pasted one App Delegate method, and moved on.

That method still works. What changed is everything around it. View controllers can now change their supported orientations while they're on screen, iPhone apps can ask the system to rotate, and iPad apps live in resizable windows where locking the orientation isn't fully up to you anymore. Here is how I'd do it today, from the simplest option to the one with the most moving parts.

Lock the whole app in the target settings

If no screen in your app should ever turn sideways, don't write code. In Xcode, select the app target, open the General tab, and under Deployment Info untick Landscape Left and Landscape Right for iPhone. Xcode writes the result into your Info.plist as the UISupportedInterfaceOrientations array, which then holds only UIInterfaceOrientationPortrait.

Newer projects don't have an Info.plist file for the app target. The same setting lives in the target's build settings as INFOPLIST_KEY_UISupportedInterfaceOrientations, so search for that name if you edit project files by hand or review a pull request. iPad has its own key, ending in _iPad, so changing the iPhone boxes leaves iPad alone.

Lock one screen in code

Most apps want something in between: everything in portrait except the video player, or everything free except the onboarding screens. For that, leave landscape enabled in the target and let each view controller say what it supports.

import UIKit

// One screen that only works in portrait
final class PortraitOnlyViewController: UIViewController {
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask { .portrait }
}

// A navigation controller asks the screen on top instead of answering for all of them
final class OrientationNavigationController: UINavigationController {
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        topViewController?.supportedInterfaceOrientations ?? .portrait
    }
}

// A screen that switches between portrait and landscape at runtime
final class VideoViewController: UIViewController {
    private var allowsLandscape = false

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        allowsLandscape ? .landscape : .portrait
    }

    func enterFullScreen() {
        allowsLandscape = true
        guard #available(iOS 16.0, *) else { return }
        setNeedsUpdateOfSupportedInterfaceOrientations()
        view.window?.windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: .landscapeRight)) { error in
            print("Rotation refused: \(error.localizedDescription)")
        }
    }

    func exitFullScreen() {
        allowsLandscape = false
        guard #available(iOS 16.0, *) else { return }
        setNeedsUpdateOfSupportedInterfaceOrientations()
        view.window?.windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: .portrait))
    }
}

// iPadOS 26 and later: ask the system to keep the orientation while the app fills the screen
final class GameViewController: UIViewController {
    @available(iOS 26.0, *)
    override var prefersInterfaceOrientationLocked: Bool { true }
}

// The app-wide limit from the 2018 post, still valid as a hard cap
final class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication,
                     supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
        .portrait
    }
}

Three parts of this matter more than they look.

  • The container decides. UIKit asks the root view controller, or the topmost one presented full screen. If your screens sit inside a UINavigationController, the navigation controller answers, and Apple's documentation says it doesn't consult the view controllers on its stack. The small subclass above forwards the question to the screen on top. The navigation controller's delegate method navigationControllerSupportedInterfaceOrientations(_:) is another way to do it. For a UITabBarController, forward to selectedViewController the same way, or use its delegate's tabBarControllerSupportedInterfaceOrientations(_:).
  • Tell UIKit when the answer changes. Since iOS 16, a view controller calls setNeedsUpdateOfSupportedInterfaceOrientations() after its supported orientations change. Without that call, UIKit keeps using the value it read before.
  • Asking for a rotation is a request. requestGeometryUpdate on the window scene asks the system to turn the screen. The system can refuse, and the error handler tells you why. It only works if the orientation you ask for is allowed by the app, the view controller and the device all at once.

The App Delegate method from the 2018 post is still there at the bottom. application(_:supportedInterfaceOrientationsFor:) returns the orientations for the whole app, replacing the Info.plist list, and UIKit only rotates when the app and the view controller agree. Apple's documentation now marks it deprecated in iOS 27 and points to a new scene delegate method, supportedInterfaceOrientations(for:) on UIWindowSceneDelegate, which does the same job for one window scene. That method needs the iOS 27 SDK, so it isn't in the code above and wasn't compiled here. Either way, I'd only reach for an app-wide method when the allowed orientations depend on something Info.plist can't express, such as a setting the user picks.

iPad is a different deal now

On iPhone you're in control. On iPad, the rules changed with iPadOS 26, and it's the part people miss when they copy an iPhone answer.

Apple's documentation for supportedInterfaceOrientations says that if your app supports multitasking, the system doesn't call that property at all, because multitasking apps must support every orientation. In 2018 the usual way out was the Requires Full Screen checkbox, which sets UIRequiresFullScreen. Apple has deprecated that key in iPadOS 26. Its technote TN3192 says it will be ignored in a future release, and that from iOS 27 and iPadOS 27 it no longer stops an app built with the iOS 27 SDK from being resized. The system resizes the app's window in steps instead.

Two newer tools replace part of what it did:

  • prefersInterfaceOrientationLocked, new in iOS 26, lets a view controller say it would like the orientation locked. The system only honors it while the app's window is centered, the same size as the screen and not covered by another app, and it drops the lock as soon as that stops being true. The game screen in the code above shows the override, with @available(iOS 26.0, *) so it still builds for older targets.
  • UISceneSizeRestrictions sets a minimum and maximum window size, so your layout never has to handle a size it wasn't designed for.

The honest answer for iPad in 2026 is to make the layout work in every orientation and size, and use those two only where a screen really can't adapt, like a camera view or a game.

A quick check before you ship

  1. Search the project for UISupportedInterfaceOrientations and UIRequiresFullScreen, in Info.plist files and in build settings. If the second one shows up in an iPad app, read TN3192 before your next SDK update.
  2. Open every screen that overrides supportedInterfaceOrientations and check what it's embedded in. A navigation or tab bar controller without forwarding quietly ignores the override.
  3. Rotate the simulator on the screen you locked, then push and pop a screen that isn't locked. That's where an outdated value usually shows up.

What the 2018 version said

The original post linked a Stack Overflow question about stopping auto-rotation, showed a screenshot of the Deployment Info checkboxes, and gave this App Delegate method returning landscape only:

func application(_ application: UIApplication,
                 supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.landscape.rawValue)
}

It still compiles with the iOS 26.2 SDK. The rawValue round trip does nothing, so return .landscape says the same thing. The method itself is on its way out in iOS 27, for one screen the per-view-controller override above is the better tool, and on iPad the system now has the last word.

Sources