Application must be Portrait on startup, but after I can rotate it.
How do this, maybe programmatically?
Application must be Portrait on startup, but after I can rotate it.
How do this, maybe programmatically?
You can add this to each controller that you would like to have in portrait mode:
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait //return the value as per the required orientation
}
Or you can set it in settings (as @Sid Mhatre already mentioned): https://stackoverflow.com/a/35285490/8382008
You could create a extension for the orientation in your appDelegate like this:
protocol MyAppDelegate: class {
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask
}
extension AppDelegate: MyAppDelegate {
func application(_ application: UIApplication,
supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return shouldRotate ? .allButUpsideDown : .portrait
}
}
In your viewControllers where you want to allow rotation you should implement this inside the viewDidLoad method:
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.shouldRotate = true
And also remove it again on viewWillDisappear:
override func viewWillDisappear(_ animated: Bool) {
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.shouldRotate = false
}