2016-12-07 7 views
1

C#、Windows phone 10の向きが変わったときに画面のボタンをソフトに回転させる方法を知っている人はいますか?Windows上の画面上のボタンを回転させる電話UWP

表示の向きが変わったときにアニメーションが表示されないように、表示の向きを縦向きまたは横向きにしたいと考えています。 DeviceOrientation.OrientationChangedイベントのすべてのコンテンツボタンを回転できますが、画面ボタンにアクセスして回転する方法があるかどうかはわかりません。

私はこの1つのように答えとしてマークされているSeveranの答えを発見した: UWP C# Disable Orientation Change Animation をそれらはすべての向きが変更されたかどうかを検出する方法について話しています。私はどのようにスクリーンボタン上でソフトを回転させるかの例を見つけることができません。

効果は、Windowsの電話のネイティブカメラのようにする必要があります。

答えて

0

あなたdevice`sの向きを取得するために方位センサを使用して、あなたのButton.Projection

参考リンクの天使設定することができます。https://msdn.microsoft.com/en-us/windows/uwp/devices-sensors/use-the-orientation-sensor

public sealed partial class MainPage : Page 
{ 
    private SimpleOrientationSensor simpleorientation; 
    private double? Current = 0; 

    public MainPage() 
    { 
     this.InitializeComponent(); 
     simpleorientation = SimpleOrientationSensor.GetDefault(); 
     if (simpleorientation != null) 
     { 
      simpleorientation.OrientationChanged += new TypedEventHandler<SimpleOrientationSensor, SimpleOrientationSensorOrientationChangedEventArgs>(OrientationChanged); 
     } 
    } 

    private async void OrientationChanged(SimpleOrientationSensor sender, SimpleOrientationSensorOrientationChangedEventArgs args) 
    { 
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,() => 
     { 
      SimpleOrientation orientation = args.Orientation; 
      switch (orientation) 
      { 
       case SimpleOrientation.NotRotated: 
        Rotate(0); 
        break; 

       case SimpleOrientation.Rotated90DegreesCounterclockwise: 
        Rotate(90); 
        break; 

       case SimpleOrientation.Rotated180DegreesCounterclockwise: 
        Rotate(180); 
        break; 

       case SimpleOrientation.Rotated270DegreesCounterclockwise: 
        Rotate(270); 
        break; 

       case SimpleOrientation.Faceup: 
        break; 

       case SimpleOrientation.Facedown: 
        break; 

       default: 

        break; 
      } 
     }); 
    } 

    private void Rotate(double value) 
    { 
     MyAnimation.From = Current; 
     MyAnimation.To = (360 - value); 
     myStoryBoard.Begin(); 
     Current = MyAnimation.To; 
    } 
} 

XAMLコード:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <Button 
     x:Name="TestButton" 
     HorizontalAlignment="Center" 
     VerticalAlignment="Center" 
     Content="button"> 
     <Button.Projection> 
      <PlaneProjection x:Name="Projection" RotationZ="0" /> 
     </Button.Projection> 
    </Button> 
    <Grid.Resources> 
     <Storyboard x:Name="myStoryBoard"> 
      <DoubleAnimation 
       x:Name="MyAnimation" 
       Storyboard.TargetName="Projection" 
       Storyboard.TargetProperty="RotationZ" 
       Duration="0:0:1" /> 
     </Storyboard> 
    </Grid.Resources> 
</Grid> 
+0

返信いただきありがとうございます。これは、私がグリッドで画面上に置くボタンをアニメーション化するだけではありませんか?私はスクリーンボタン上でハードウェアを回転させる方法に興味があります。 – user2081328

関連する問題