Home > Blockchain >  Disabling landscape orientation programatically in swift IOS
Disabling landscape orientation programatically in swift IOS

Time:01-31

I want to keep support for both landscape and portrait orientation in General - > iphone orientation. However, when the app runs, I am making a start up call and based on a flag in the response , I want to disable landscape orientation or keep it throughout the app.

How can I programatically enable or disable landscape orientation?

CodePudding user response:

In your view controller try overriding these properties like below:

override public var shouldAutorotate: Bool {
    return false
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .portrait
}

CodePudding user response:

You may refer this apple documentation

As the requirement is to lock the application orientation based on the api response you can programatically handle it in the application delegate method

optional func application(
_ application: UIApplication,
supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask
  • Related