强制在纵向状态下旋转UIViewController

问题描述 投票:1回答:1

在此环境中(修复支持方向是项目配置中的纵向)

enter image description here

你能在Landscape中展示一个特定的UIViewController吗?

ios objective-c uiviewcontroller landscape device-orientation
1个回答
1
投票

简短的回答是,你不能因为根据Apple docs here

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

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

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

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

UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
© www.soinside.com 2019 - 2024. All rights reserved.