How to lock Screen Orientation programmatically in iOS?

iOSApps/ApplicationsMobile DevelopmentSwift

You might come across a scenario where you need to show the UI in a specific orientation may be Landscape or Portrait.

We will be seeing how to lock orientation programmatically using Swift in iOS.

Open Xcode → New Project → ViewController.swift write the below code.

// Set the shouldAutorotate to False
override open var shouldAutorotate: Bool {
   return false
}

// Specify the orientation.
override open var supportedInterfaceOrientations: UIInterfaceOrientationMask {
   return .portrait
}

raja
Updated on 30-Jul-2019 22:30:25

Advertisements