如何在 xcode ui 测试中使用 Swift 代码旋转模拟器
How to rotate simulator using Swift code in xcode ui test
我有一个场景,我必须在 xcode ui 测试进行时旋转我的模拟器。
为了旋转模拟器,我使用下面的代码
UIDevice.currentDevice().orientation
let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
但它不起作用。
在 xcode ui 测试中使用 Swift 代码旋转模拟器有什么解决方案吗?
你试过吗?
Swift 2.x
XCUIDevice.sharedDevice().orientation = .LandscapeLeft
XCUIDevice.sharedDevice().orientation = .Portrait
Swift 3.0
XCUIDevice.shared().orientation = .landscapeLeft
XCUIDevice.shared().orientation = .portrait
Swift 5.x
XCUIDevice.shared.orientation = .landscapeLeft
XCUIDevice.shared.orientation = .portrait
Swift 4:
XCUIDevice.shared.orientation = .landscapeLeft
XCUIDevice.shared.orientation = .portrait
我有一个场景,我必须在 xcode ui 测试进行时旋转我的模拟器。
为了旋转模拟器,我使用下面的代码
UIDevice.currentDevice().orientation
let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
但它不起作用。
在 xcode ui 测试中使用 Swift 代码旋转模拟器有什么解决方案吗?
你试过吗?
Swift 2.x
XCUIDevice.sharedDevice().orientation = .LandscapeLeft
XCUIDevice.sharedDevice().orientation = .Portrait
Swift 3.0
XCUIDevice.shared().orientation = .landscapeLeft
XCUIDevice.shared().orientation = .portrait
Swift 5.x
XCUIDevice.shared.orientation = .landscapeLeft
XCUIDevice.shared.orientation = .portrait
Swift 4:
XCUIDevice.shared.orientation = .landscapeLeft
XCUIDevice.shared.orientation = .portrait