向 Windows Phone 8 应用程序添加方向更改动画的最简单方法是什么?我对消息、日历等本机应用程序中的东西感兴趣。我一直在寻找一种快速而简单的解决方案,我发现唯一有效的是 NuGet 中的 DynamicOrientionChanges 库,但它在 Windows 上的帧率存在巨大问题电话 8.
您可以使用 Windows.Phone.Toolkit 并处理 OrientationChangedEvent,如下所示:
http://mobileworld.appamundi.com/blogs/andywigley/archive/2010/11/23/windows-phone-7-page-orientation-change-animations.aspx http://mobileworld.appamundi.com/blogs/andywigley/archive/2010/11/23/windows-phone-7-page-orientation-change-animations.aspx
我将在此处复制链接文章的源代码部分,以防页面离线。它包含额外的逻辑来跟踪当前方向来自哪个方向,以便动画与变化相匹配:
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;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)