横向模式下的 SafariViewController

SafariViewController in Landscape Mode

我有一个 ViewController 仅处于纵向模式。它展示了一个 SafariViewController。是否可以将 SafariViewController 的方向更改为横向,同时保持 ViewController 的纵向?

这适用于 Swift 4.2。您必须在 viewController 中添加此方法以保持纵向

override var supportedInterfaceOrientations:UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.portrait
}

而且您还必须声明

let appDelegate = UIApplication.shared.delegate as! AppDelegate

同样在您的 AppDelegate 中,您必须添加

var myOrientation: UIInterfaceOrientationMask = .portrait

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    return myOrientation
}

以及创建 SFSafariViewController 时的这个

let appDelegate = UIApplication.shared.delegate as! AppDelegate
    appDelegate.myOrientation = .all