WP8方向改变动画 [英] WP8 Orientation change animations

查看:106
本文介绍了WP8方向改变动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是方向改变动画添加到我的Windows Phone 8应用程序最简单的方法?我感兴趣的东西,看起来像在诸如邮件,日历,等等。我一直在寻找一个快速和简单的解决方案,我发现工作是在DynamicOrientionChanges库的NuGet唯一原生应用,但它在Windows帧率一个巨大的问题Phone 8的。

What is the easiest way to add orientation change animations to my Windows Phone 8 application? I am interested in something that looks like in native apps like Messages, Calendar, etc. I was looking for a quick and simple solution and the only thing I found working was DynamicOrientionChanges library in NuGet, but it has a huge problem with framerate on Windows Phone 8.

推荐答案

您可以使用Windows.Phone.Toolkit和处理OrientationChangedEvent,这里展出了:

You can use the Windows.Phone.Toolkit and handle the OrientationChangedEvent, as showcased here:

<一个href=\"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

我会在这里复制链接文章来源$ C ​​$ C部分,以防万一页面脱机。它包括额外的逻辑来跟踪从哪个方向当前人来,使动画的变化相匹配

I'll copy the source code part of the linked article here, just in case the page goes offline. It includes additional logic to track from which orientation the current one came, so that the animation matches the change:

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;
    }
}

这篇关于WP8方向改变动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆