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

単純な向きセンサーが新しいセンサーの読み取りを報告するたびに発生します

適用対象

こちらもご覧ください