【问题标题】:Force rotate UIViewController in Portrait status在 Portrait 状态下强制旋转 UIViewController
【发布时间】:2018-09-05 02:10:28
【问题描述】:

在这种环境下 (修复项目配置中支持方向为纵向)

你能在 Landscape 中显示特定的 UIViewController 吗?

【问题讨论】:

    标签: ios objective-c uiviewcontroller landscape device-orientation


    【解决方案1】:

    简短的回答是你不能因为根据苹果文档here

    系统与视图控制器支持的方向相交 应用程序支持的方向(由 Info.plist 确定 文件或应用程序委托的 application(_:supportedInterfaceOrientationsFor:) 方法)和 设备支持的方向来确定是否旋转。

    要实现您所需要的,您也应该将允许的方向设置为横向,然后在您的视图控制器中实现以下内容以允许纵向或横向(或两者):

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.portrait//or UIInterfaceOrientationMask.landscape
      }
    

    然后要强制特定方向,您可以将方向设置为 UIDevice:

    UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
    

    【讨论】:

    • 谢谢。您的建议对解决问题很有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 2012-12-02
    • 2011-11-18
    • 1970-01-01
    • 2011-01-08
    相关资源
    最近更新 更多