I am designing an universal app and I like to support portrait only for both iPhone and iPad. But I need iPad to support both regular and upside down portrait orientation.
So I set Supported interface orientations for both iPhone and iPad in info.plist
as Portrait (top home button)
and Portrait (bottom home button).
Following in AppDeleagte.swift
var shouldSupportAllOrientation = false
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if (shouldSupportAllOrientation == true){
return UIInterfaceOrientationMask.all
}
return UIInterfaceOrientationMask.portrait
}
Following in ViewController.swift
override func viewWillAppear(_ animated: Bool) {
let appdelegate = UIApplication.shared.delegate as! AppDelegate
appdelegate.shouldSupportAllOrientation = false
let value = UIInterfaceOrientation.portraitUpsideDown.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
}
When I rotate my iPad upside down in simulator, it still remains upside down and does not rotate 180 degrees. Where am I going wrong?