4
向我的Windows Phone 8应用程序添加方向更改动画最简单的方法是什么?我对消息,日历等原生应用程序感兴趣。我正在寻找一个快速简单的解决方案,我发现的唯一工作是NuGet中的DynamicOrientionChanges库,但它在Windows上的帧率有一个很大的问题电话8.WP8方向更改动画
向我的Windows Phone 8应用程序添加方向更改动画最简单的方法是什么?我对消息,日历等原生应用程序感兴趣。我正在寻找一个快速简单的解决方案,我发现的唯一工作是NuGet中的DynamicOrientionChanges库,但它在Windows上的帧率有一个很大的问题电话8.WP8方向更改动画
您可以使用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;
}
}