Once your controller will call, first it will change deviceOrientation variable in landscape and change its orientation into Landscape.
You can find the final project here:
Declare a variable, set its name deviceOrientation. It would be Portrait by default when application will launch or you may change it as per your app requirements.
import UIKit
let appDelegate = UIApplication.shared.delegate as! AppDelegate
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var deviceOrientation = UIInterfaceOrientationMask.portrait
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return deviceOrientation
}
}
Now, in your designated or specific view controller you have to change your viewWillAppear method like that:
override func viewWillAppear(_ animated: Bool) {
appDelegate.deviceOrientation = .landscapeLeft
let value = UIInterfaceOrientation.landscapeLeft.rawValue
UIDevice.current.setValue(value, forKey: “orientation”)
}
Once your controller will call, first it will change deviceOrientation variable in landscape and change its orientation into Landscape.
You can find the final project here: