SimpleOrientationSensor 클래스

정의

간단한 방향 센서를 나타냅니다.

구현의 예는 단순 방향 센서 샘플을 참조하세요.

이 센서는 지정된 디바이스의 현재 사분면 방향과 페이스업 또는 페이스다운 상태 감지합니다.

public ref class SimpleOrientationSensor sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class SimpleOrientationSensor final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class SimpleOrientationSensor
Public NotInheritable Class SimpleOrientationSensor
상속
Object Platform::Object IInspectable SimpleOrientationSensor
특성

Windows 요구 사항

디바이스 패밀리
Windows 10 (10.0.10240.0에서 도입되었습니다.)
API contract
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)

설명

다음 예제에서는 XAML 및 C#으로 빌드된 UWP 앱이 GetDefault 메서드를 사용하여 간단한 방향 센서에 대한 연결을 설정하는 방법을 보여 줍니다. 간단한 방향 센서가 없으면 메서드는 null 값을 반환합니다.

_sensor = SimpleOrientationSensor.GetDefault();

다음 예제에서는 XAML을 사용하여 빌드된 UWP 앱이 OrientationChanged 이벤트 처리기를 등록하는 방법을 보여 줍니다.

private void ScenarioEnable(object sender, RoutedEventArgs e)
{
    if (_sensor != null)
    {
        Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
        _sensor.OrientationChanged += new TypedEventHandler<SimpleOrientationSensor, SimpleOrientationSensorOrientationChangedEventArgs>(OrientationChanged);

        ScenarioEnableButton.IsEnabled = false;
        ScenarioDisableButton.IsEnabled = true;

        // Display the current orientation once while waiting for the next orientation change
        DisplayOrientation(ScenarioOutput_Orientation, _sensor.GetCurrentOrientation());
    }
    else
    {
        rootPage.NotifyUser("No simple orientation sensor found", NotifyType.StatusMessage);
    }
}

다음 예제에는 애플리케이션의 양식에 방향 판독값을 쓰는 이벤트 처리기에 대한 XAML 코드가 포함되어 있습니다.

async private void OrientationChanged(object sender, SimpleOrientationSensorOrientationChangedEventArgs e)
{
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {
        DisplayOrientation(ScenarioOutput_Orientation, e.Orientation);
    });
}
private void DisplayOrientation(TextBlock tb, SimpleOrientation orientation)
{
    switch (orientation)
    {
        case SimpleOrientation.NotRotated:
            tb.Text = "Not Rotated";
            break;
        case SimpleOrientation.Rotated90DegreesCounterclockwise:
            tb.Text = "Rotated 90 Degrees Counterclockwise";
            break;
        case SimpleOrientation.Rotated180DegreesCounterclockwise:
            tb.Text = "Rotated 180 Degrees Counterclockwise";
            break;
        case SimpleOrientation.Rotated270DegreesCounterclockwise:
            tb.Text = "Rotated 270 Degrees Counterclockwise";
            break;
        case SimpleOrientation.Faceup:
            tb.Text = "Faceup";
            break;
        case SimpleOrientation.Facedown:
            tb.Text = "Facedown";
            break;
        default:
            tb.Text = "Unknown orientation";
            break;
    }
}

버전 기록

Windows 버전 SDK 버전 추가된 값
1809 17763 FromIdAsync
1809 17763 GetDeviceSelector

속성

DeviceId

SimpleOrientationSensor.FromIdAsync 메서드에 사용되는 디바이스 식별자를 가져옵니다.

ReadingTransform

센서 데이터에 적용해야 하는 변환을 가져오거나 설정합니다. 적용할 변환은 센서 데이터를 정렬할 디스플레이 방향에 연결됩니다.

메서드

FromIdAsync(String)

지정된 디바이스 식별자를 기반으로 SimpleOrientationSensor 개체를 비동기적으로 검색합니다.

GetCurrentOrientation()

기본 단순 방향 센서를 가져옵니다.

GetDefault()

기본 단순 방향 센서를 가져옵니다.

GetDeviceSelector()

사용 가능한 SimpleOrientationSensor 디바이스를 열거하는 데 사용되는 AQS(고급 쿼리 구문) 문자열을 검색합니다.

이벤트

OrientationChanged

간단한 방향 센서가 새 센서 판독값을 보고할 때마다 발생합니다.

적용 대상

추가 정보