当设备改变位置时,我试图在横向模式下的应用程序中仅创建一个 View ,而不是从一开始就创建一个 View 。其余 View 以纵向方式工作。
AppDelegate
internal var shouldRotate = false
func application(_ application: UIApplication,
supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return shouldRotate ? .allButUpsideDown : .portrait
}
viewDidLoad
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.shouldRotate = true
这可行,但它适用于我的所有页面,而我只想要一个特定的页面
最佳答案
在您想要仅横向的 View Controller 中,覆盖 supportedInterfaceOrientations
并提供横向的 OptionSet
:
public override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return [.landscapeLeft, .landscapeRight]
}
关于ios - 一页横向模式 swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47945536/