2016-09-26 27 views
9

我有一个场景,我必须旋转我的模拟器,而xcode ui测试正在进行。如何旋转模拟器使用xcode中的swift代码ui test

要旋转模拟器,我用下面的代码

UIDevice.currentDevice().orientation 
let value = UIInterfaceOrientation.LandscapeLeft.rawValue 
UIDevice.currentDevice().setValue(value, forKey: "orientation") 

,但它无法正常工作。

是否有任何解决方案在xcode ui测试中使用swift代码旋转模拟器?

谢谢

+0

尝试此[如何旋转模拟器(http://stackoverflow.com/问题/ 15642135/how-do-i-rotate-the-ios-simulator-using-code) – iDeveloper

回答

12

你试过吗?

夫特2.x的

XCUIDevice.sharedDevice().orientation = .LandscapeLeft 
XCUIDevice.sharedDevice().orientation = .Portrait 

夫特3.0

XCUIDevice.shared().orientation = .landscapeLeft 
XCUIDevice.shared().orientation = .portrait 
+1

谢谢,它的工作就像我所希望的那样 – user6633897

+0

Np gl广告帮助@ user6633897 –

+0

** @ Rashwan **如果我想在控制台中打印模拟器的状态? – iDeveloper

0

夫特4:

XCUIDevice.shared.orientation = .landscapeLeft 
XCUIDevice.shared.orientation = .portrait