我有一个仅在纵向模式下的ViewController。它呈现了一个SafariViewController。是否可以将SafariViewController的方向更改为Landscape来维护ViewController的Portrait?
这适用于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