2016-12-07 71 views
1

有沒有人知道如何在C#,Windows Phone 10中改變方向時在屏幕按鈕上旋轉軟鍵?在windows phone上旋轉軟屏幕按鈕UWP

我希望將顯示方向保持爲縱向或橫向,以避免在顯示方向改變時進行動畫。我可以旋轉DeviceOrientation.OrientationChanged事件上的所有內容按鈕,但我不知道是否有訪問和旋轉屏幕按鈕的方法。

我發現severan答案被標記爲像這樣回答: UWP C# Disable Orientation Change Animation 但他們都談論如何檢測方向是否改變。我無法找到任何有關如何在屏幕按鈕上旋轉柔和的示例。

效果應該像在windows phone本機相機上。

回答

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