将方向更改动画添加到Windows Phone 8应用程序的最简单方法是什么?我感兴趣的东西看起来像本地应用程序,如消息,日历等。我一直在寻找一个快速简单的解决方案,我发现唯一的工作是NuGet中的DynamicOrientionChanges库,但它在Windows上的帧速率有一个巨大的问题电话8。
答案 0 :(得分:5)
您可以使用Windows.Phone.Toolkit并处理OrientationChangedEvent,如下所示:
我将在此处复制链接文章的源代码部分,以防页面脱机。它包含用于跟踪当前方向的附加逻辑,以便动画与更改匹配:
public partial class MainPage : PhoneApplicationPage
{
PageOrientation lastOrientation;
// Constructor
public MainPage()
{
InitializeComponent();
this.OrientationChanged += new EventHandler<OrientationChangedEventArgs>(MainPage_OrientationChanged);
lastOrientation = this.Orientation;
}
void MainPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
PageOrientation newOrientation = e.Orientation;
Debug.WriteLine("New orientation: " + newOrientation.ToString());
// Orientations are (clockwise) 'PortraitUp', 'LandscapeRight', 'LandscapeLeft'
RotateTransition transitionElement = new RotateTransition();
switch (newOrientation)
{
case PageOrientation.Landscape:
case PageOrientation.LandscapeRight:
// Come here from PortraitUp (i.e. clockwise) or LandscapeLeft?
if (lastOrientation == PageOrientation.PortraitUp)
transitionElement.Mode = RotateTransitionMode.In90Counterclockwise;
else
transitionElement.Mode = RotateTransitionMode.In180Clockwise;
break;
case PageOrientation.LandscapeLeft:
// Come here from LandscapeRight or PortraitUp?
if (lastOrientation == PageOrientation.LandscapeRight)
transitionElement.Mode = RotateTransitionMode.In180Counterclockwise;
else
transitionElement.Mode = RotateTransitionMode.In90Clockwise;
break;
case PageOrientation.Portrait:
case PageOrientation.PortraitUp:
// Come here from LandscapeLeft or LandscapeRight?
if (lastOrientation == PageOrientation.LandscapeLeft)
transitionElement.Mode = RotateTransitionMode.In90Counterclockwise;
else
transitionElement.Mode = RotateTransitionMode.In90Clockwise;
break;
default:
break;
}
// Execute the transition
PhoneApplicationPage phoneApplicationPage = (PhoneApplicationPage)(((PhoneApplicationFrame)Application.Current.RootVisual)).Content;
ITransition transition = transitionElement.GetTransition(phoneApplicationPage);
transition.Completed += delegate
{
transition.Stop();
};
transition.Begin();
lastOrientation = newOrientation;
}
}