【发布时间】:2019-03-08 11:22:59
【问题描述】:
我有一个仅处于纵向模式的 ViewController。它提供了一个 SafariViewController。是否可以将 SafariViewController 的方向更改为横向维护 ViewController 的纵向?
【问题讨论】:
标签: swift orientation sfsafariviewcontroller
我有一个仅处于纵向模式的 ViewController。它提供了一个 SafariViewController。是否可以将 SafariViewController 的方向更改为横向维护 ViewController 的纵向?
【问题讨论】:
标签: swift orientation sfsafariviewcontroller
这适用于 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
【讨论】: