Dela via


SimpleOrientationSensor.GetCurrentOrientation Method

Definition

Gets the default simple orientation sensor.

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

Returns

The default simple orientation sensor.

Remarks

An application may use this method to poll the sensor for the current reading as an alternative to registering a OrientationChanged event handler. This would be the preferred alternative for an application that updates its user interface at a specific frame rate.

The following example demonstrates how a UWP app built for Windows using JavaScript retrieved the current device orientation by using the simple orientation sensor.

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");
    }
}

Applies to