我有一个项目,我的屏幕需要在横向和纵向方向上进行测试,并且需要在我运行一些 UI 测试用例时自动发生,我使用以下代码。
let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
这在 iPhone 模拟器上运行良好,模拟器将自身转为横向模式,但在 iPad 模拟器上不会自行旋转
我尝试过的事情: 将以下代码添加到
UIViewController.attemptRotationToDeviceOrientation()
也没有工作并检查方向是否受 iPad 支持或不使用:
self.supportedInterfaceOrientations
返回 30(支持所有方向)