gpt4 book ai didi

ios - 在 UIAutomation 中获取设备方向

转载 作者:行者123 更新时间:2023-11-28 18:38:55 25 4
gpt4 key购买 nike

我正在为我的程序编写自动化测试,并希望自动执行设备方向......我正在使用下面的代码来设置设备的方向,

UIATarget.localTarget().setDeviceOrientation(UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT);

但我也希望获得设备的当前方向。我找不到任何 getDeviceOrientation() 方法来获取方向。

最佳答案

你试过吗:

var orientation = UIATarget.localTarget().deviceOrientation()

来自documentation :

deviceOrientation

Discussion

The returned value is a constant that represents the physical orientation of the device and may be different from the current orientation of your app’s user interface. The possible values are as follows:

UIA_DEVICE_ORIENTATION_UNKNOWN
UIA_DEVICE_ORIENTATION_PORTRAIT
UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN
UIA_DEVICE_ORIENTATION_LANDSCAPELEFT
UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT
UIA_DEVICE_ORIENTATION_FACEUP
UIA_DEVICE_ORIENTATION_FACEDOWN

编辑

设备方向可能在模拟器上不可用。最好在 UIAApplication 对象上使用 interfaceOrientation()

var target = UIATarget.localTarget();
var app = target.frontMostApp();
var orientation = app.interfaceOrientation();

if (orientation == UIA_INTERFACE_ORIENTATION_PORTRAIT || orientation == UIA_INTERFACE_ORIENTATION_PORTRAIT_UPSIDEDOWN) {
UIALogger.logDebug("Portrait");
} else if (orientation == UIA_INTERFACE_ORIENTATION_LANDSCAPELEFT || orientation == UIA_INTERFACE_ORIENTATION_LANDSCAPERIGHT) {
UIALogger.logDebug("Landscape");
}

This guide还不错。

关于ios - 在 UIAutomation 中获取设备方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13866018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com