4

向我的 Windows Phone 8 应用程序添加方向更改动画的最简单方法是什么?我对类似于消息、日历等本机应用程序的东西感兴趣。我一直在寻找一种快速简单的解决方案,我发现唯一有效的是 NuGet 中的 DynamicOrientionChanges 库,但它在 Windows 上的帧率存在很大问题电话 8。

4

1 回答 1

5

您可以使用 Windows.Phone.Toolkit 并处理 OrientationChangedEvent,如下所示:

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;
    }
}
于 2013-11-19T22:22:36.493 回答