横向模式下的SafariViewController

时间:2019-03-08 11:23:00

标签: swift orientation sfsafariviewcontroller

我有一个仅在纵向模式下的ViewController。它提供了一个SafariViewController。可以将SafariViewController的方向更改为Landscape,以维持ViewController的Portrait吗?

1 个答案:

答案 0 :(得分:0)

这适用于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