我正在尝试使用 XCTestCase 在不同方向测试我的 iOS 应用程序。我需要一种以编程方式改变方向的方法。我尝试用两种方法进行此操作,但都没有改变方向(方向保持为 UIInterfaceOrientationPortrait)。
尝试 1
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;`
尝试 2
[[UIDevice currentDevice] setValue:[NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];`
当我阅读 [[UIApplication sharedApplication] statusBarOrientation] 是否有另一种方法可以更改方向以进行测试?
最佳答案
快速代码:
XCUIDevice.shared.orientation = UIDeviceOrientation.portrait;
关于ios - 如何更改 XCTest for iOS 测试的方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35634182/