【问题标题】:WP8 Orientation change animationsWP8 方向改变动画
【发布时间】:2023-12-12 07:31:01
【问题描述】:

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

【问题讨论】:

    标签: animation windows-phone-8


    【解决方案1】:

    您可以使用 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;
        }
    }
    

    【讨论】: