ios - 一页横向模式 swift

标签 ios swift

当设备改变位置时,我试图在横向模式下的应用程序中仅创建一个 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/

相关文章:

ios - 如何检查 Google/Facebook 帐户是否已用于在 Firebase Auth 上创建帐户

ios - 如何更改didSelectRowAtIndexPath中单元格的背景图像

ios - SDWebImage 不更新缓存中的图像

ios 快速将图像发布到 linkedin

ios - 如何在Moscapsule(swift mqtt库)中设置最后的遗嘱消息?

iphone - 动画 UITableViewCell 高度和单元格 backgroundView

Swift:将 AsyncStream 映射到另一个 AsyncStream

swift - xcode 上的自定义 uislider

ios - 在应用程序运行时获取用户位置,并在使用按钮四处移动后再次重新居中

ios - 未调用第二个 ViewController 中的委托(delegate)方法