skip to Main Content

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?

2

Answers


  1. In your view controller try overriding these properties like below:

    override public var shouldAutorotate: Bool {
        return false
    }
    
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .portrait
    }
    
    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search