2016-12-07 18 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