Mey*_*pan 4 objective-c ios xctest xctestcase
我正在尝试使用XCTestCase在不同方向上测试我的iOS应用。我需要一种以编程方式更改方向的方法。我尝试使用2种方法进行此操作,但两种方法均未更改方向(方向仍为UIInterfaceOrientationPortrait)。
尝试1
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;`
Run Code Online (Sandbox Code Playgroud)
尝试2
[[UIDevice currentDevice] setValue:[NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];`
Run Code Online (Sandbox Code Playgroud)
当我阅读[[UIApplication sharedApplication] statusBarOrientation]时,是否还有另一种方法可以更改方向以进行测试?
小智 6
使用下面的解决方案。在设置方法中执行此操作。
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
forKey:@"orientation"];
Run Code Online (Sandbox Code Playgroud)
它对我有用。
SWIFT代码:
XCUIDevice.shared.orientation = UIDeviceOrientation.portrait;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1884 次 |
| 最近记录: |