我有一个仅在纵向模式下的ViewController。它提供了一个SafariViewController。可以将SafariViewController的方向更改为Landscape,以维持ViewController的Portrait吗?
答案 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