i have a ViewController that is only in Portrait mode. It presents a SafariViewController. Is it possible to change the orientation of the SafariViewController to Landscape maintaining the Portrait for the ViewController?
Asked
Active
Viewed 700 times
1 Answers
0
This works with Swift 4.2. You have to add this method in your viewController to maintain portrait orientation
override var supportedInterfaceOrientations:UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait
}
and you also must declare
let appDelegate = UIApplication.shared.delegate as! AppDelegate
Also in your AppDelegate you have to add
var myOrientation: UIInterfaceOrientationMask = .portrait
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return myOrientation
}
and this when you are creating the SFSafariViewController
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.myOrientation = .all

Andrea Culot
- 114
- 2
- 9