Windows Phone 7两个页面动画跳转
2012-02-08 16:15
218 查看
两个页面之间创建带有动画的过渡效果基本步骤:
①截获当前任何表明用户正在离开当前页面的操作
②启动一个动画故事板来隐藏当前页面
③导航到下一个页面
④截获新页面的导航
⑤启动一个动画故事板来显示新页面
首先新建一个Windows Phone的应用程序
MainPage.xaml里面的动画效果代码:
复制代码
然后拖一个Button控件,并触发Click事件,导航到Page1.xaml
复制代码
在MainPage.xaml.cs里面重写OnNavigatingFrom方法:
复制代码
接着新建一个WindowsPhone页面Page1.xaml
Page1.xaml的动画效果代码如下:
复制代码
然后在Page1.xaml.cs的初始化函数里写如下代码:
复制代码
就这样,一个最基本的两个页面动画跳转效果就做好了
①截获当前任何表明用户正在离开当前页面的操作
②启动一个动画故事板来隐藏当前页面
③导航到下一个页面
④截获新页面的导航
⑤启动一个动画故事板来显示新页面
首先新建一个Windows Phone的应用程序
MainPage.xaml里面的动画效果代码:
<phone:PhoneApplicationPage.Resources> <Storyboard x:Name="HidePage"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="phoneApplicationPage"> <EasingDoubleKeyFrame KeyTime="0" Value="0"/> <EasingDoubleKeyFrame KeyTime="0:0:2" Value="-480"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="phoneApplicationPage"> <EasingDoubleKeyFrame KeyTime="0" Value="0"/> <EasingDoubleKeyFrame KeyTime="0:0:2" Value="-800"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </phone:PhoneApplicationPage.Resources> <phone:PhoneApplicationPage.RenderTransform> <CompositeTransform/> </phone:PhoneApplicationPage.RenderTransform>
复制代码
然后拖一个Button控件,并触发Click事件,导航到Page1.xaml
private void button1_Click(object sender, RoutedEventArgs e) { this.NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative)); }
复制代码
在MainPage.xaml.cs里面重写OnNavigatingFrom方法:
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e) { base.OnNavigatingFrom(e); if (UriToNavigateTo == null) { e.Cancel = true; UriToNavigateTo = e.Uri; this.HidePage.Begin(); this.HidePage.Completed += new EventHandler(HidePage_Completed); } else { UriToNavigateTo = null; } } private void HidePage_Completed(object sender, EventArgs e) { this.NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative)); }
复制代码
接着新建一个WindowsPhone页面Page1.xaml
Page1.xaml的动画效果代码如下:
<phone:PhoneApplicationPage.Resources> <Storyboard x:Name="DisplayPage"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="phoneApplicationPage"> <EasingDoubleKeyFrame KeyTime="0" Value="0"/> <EasingDoubleKeyFrame KeyTime="0:0:3" Value="1"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="phoneApplicationPage"> <EasingDoubleKeyFrame KeyTime="0" Value="0"/> <EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="phoneApplicationPage"> <EasingDoubleKeyFrame KeyTime="0" Value="-720"/> <EasingDoubleKeyFrame KeyTime="0:0:2" Value="0"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </phone:PhoneApplicationPage.Resources> <phone:PhoneApplicationPage.RenderTransform> <CompositeTransform CenterX="240" CenterY="400"/> </phone:PhoneApplicationPage.RenderTransform>
复制代码
然后在Page1.xaml.cs的初始化函数里写如下代码:
public Page1() { InitializeComponent(); this.DisplayPage.Begin(); }
复制代码
就这样,一个最基本的两个页面动画跳转效果就做好了
相关文章推荐
- Windows Phone 7两个页面动画跳转
- Windows Phone 7两个页面动画跳转
- Windows Phone页面动画跳转
- Windows Phone下页面跳转动画的实现
- Windows phone中如何添加页面跳转动画
- Windows Phone下页面跳转动画的实现
- Windows Phone 7开发的页面动画跳转【转】
- Windows phone中如何添加页面跳转动画
- Cocos 页面跳转随机动画崩溃
- WP开发笔记——WP APP添加页面跳转动画
- 从带有启动动画的欢迎页面SplashActivity跳转到MainActivity
- 一起学Windows phone 7开发(二.页面间跳转与传值)
- windows phone 7 用户控件页面跳转
- WP学习笔记(1)页面跳转动画
- iPhone页面跳转动画的封装
- 关于加载cocos2dx动画问题,跳转页面后回来不显示,报错找不到资源
- Windows phone 7开发(二.页面间跳转与传值)
- 页面跳转动画设置方法
- 页面跳转动画 For_Cocos2d-iphone
- 根据条件,切换 Windows Phone 的页面跳转