Hi there,
I use SafariServices to show a webpage. So the challenge is to use the landscape mode only with the SafariController.
In the project settings the "Device Orientation" is set to "Portrait".
Do someone know a solution for this?
I use SafariServices to show a webpage. So the challenge is to use the landscape mode only with the SafariController.
Code Block import SafariServices let config = SFSafariViewController.Configuration() config.entersReaderIfAvailable = true config.barCollapsingEnabled = false let vc = SFSafariViewController(url: url, configuration: config) present(vc, animated: true)
In the project settings the "Device Orientation" is set to "Portrait".
Do someone know a solution for this?
I've developed the following solution:
3. Programmatically created SFSafariViewController in the ViewController:
The Device Orientation in the Deployment Info in the settings is not set (no checkbox is checked).
AppDelegate: the one controller in this case is "SFSafariViewController"
Code Block //rotation 1 func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { if let rootViewController = self.topViewControllerWithRootViewController(rootViewController: window?.rootViewController) { print(rootViewController) if (rootViewController is SFSafariViewController) { // Unlock landscape view orientations for this view controller print("unlock") return .allButUpsideDown; } } //Only allow portrait (standard behaviour) return .portrait; } //rotation 2 private func topViewControllerWithRootViewController(rootViewController: UIViewController!) -> UIViewController? { if (rootViewController == nil) { return nil } if (rootViewController.isKind(of: UITabBarController.self)) { return topViewControllerWithRootViewController(rootViewController: (rootViewController as! UITabBarController).selectedViewController)} else if (rootViewController.isKind(of: UINavigationController.self)) { return topViewControllerWithRootViewController(rootViewController: (rootViewController as! UINavigationController).visibleViewController) } else if (rootViewController.presentedViewController != nil) { return topViewControllerWithRootViewController(rootViewController: rootViewController.presentedViewController) } return rootViewController }
3. Programmatically created SFSafariViewController in the ViewController:
Code Block import SafariServices let url = URL(string : file_url)! let config = SFSafariViewController.Configuration() config.entersReaderIfAvailable = true config.barCollapsingEnabled = false let vc = SFSafariViewController(url: url, configuration: config) present(vc, animated: true)