SimpleOrientationSensor.GetCurrentOrientation 方法

定义

获取默认的简单方向传感器。

public:
 virtual SimpleOrientation GetCurrentOrientation() = GetCurrentOrientation;
SimpleOrientation GetCurrentOrientation();
public SimpleOrientation GetCurrentOrientation();
function getCurrentOrientation()
Public Function GetCurrentOrientation () As SimpleOrientation

返回

默认的简单方向传感器。

注解

应用程序可以使用此方法轮询传感器以获取当前读数,作为注册 OrientationChanged 事件处理程序的 替代方法。 这将是以特定帧速率更新其用户界面的应用程序的首选替代方法。

以下示例演示使用 JavaScript 为 Windows 生成的 UWP 应用如何使用简单的方向传感器检索当前设备方向。

function invokeGetReadingScenario() {
    if (sensor) {
        var orientation = sensor.getCurrentOrientation();

        switch (orientation) {
            case Windows.Devices.Sensors.SimpleOrientation.notRotated:
                document.getElementById("readingOutputOrientation").innerHTML = "Not Rotated";
                break;
            case Windows.Devices.Sensors.SimpleOrientation.rotated90DegreesCounterclockwise:
                document.getElementById("readingOutputOrientation").innerHTML = "Rotated 90";
                break;
            case Windows.Devices.Sensors.SimpleOrientation.rotated180DegreesCounterclockwise:
                document.getElementById("readingOutputOrientation").innerHTML = "Rotated 180";
                break;
            case Windows.Devices.Sensors.SimpleOrientation.rotated270DegreesCounterclockwise:
                document.getElementById("readingOutputOrientation").innerHTML = "Rotated 270";
                break;
            case Windows.Devices.Sensors.SimpleOrientation.faceup:
                document.getElementById("readingOutputOrientation").innerHTML = "Face Up";
                break;
            case Windows.Devices.Sensors.SimpleOrientation.facedown:
                document.getElementById("readingOutputOrientation").innerHTML = "Face Down";
                break;
            default:
                document.getElementById("readingOutputOrientation").innerHTML = "Undefined orientation " + orientation;
                break;
        }
    } else {
        WinJS.log && WinJS.log("No simple orientation sensor found", "sample", "error");
    }
}

适用于