模仿WP7解锁页面动画

发布于 2024-12-05 23:07:22 字数 79 浏览 0 评论 0原文

在我的应用程序中,我需要创建 wp7 页面解锁动画(即向上滑动图片并解锁设备),如何在我的应用程序中借助 xaml 或 C# 代码来实现该动画。

In my app, i need to create wp7 page unloak animation(ie sliding up the picture and unloak the device) how i can implement that in my app either with the help of xaml or with the help of C# code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谷夏 2024-12-12 23:07:22

实现wp7页面解锁动画的步骤如下

1.创建以下故事板

 <Storyboard x:Name="LockScreenSlideAnimation">
       <DoubleAnimation Duration="0:0:1" To="-768"  
       Storyboard.TargetProperty="  
       (UIElement.RenderTransform).  
       (CompositeTransform.TranslateY)" 
       Storyboard.TargetName="LockScreenGrid" d:IsOptimized="True"/>
 </Storyboard>

    <Storyboard x:Name="CoastGrid" >
 <DoubleAnimationUsingKeyFrames 
   Storyboard.TargetName="LockScreenGrid"                      

    Storyboard.TargetProperty="(UIElement.RenderTransform)
    .(CompositeTransform.TranslateY)">
                    <EasingDoubleKeyFrame x:Name="coastY"           
            KeyTime="00:00:01" Value="0">
                    </EasingDoubleKeyFrame>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>

2.假设网格名称为 LockScreenGrid [点击时会飞起来的图像网格]

<Grid Grid.Row="1" x:Name="LockScreenGrid" Visibility="{Binding        

  LockScreenGridVisibility}"
   ManipulationDelta="lock_ManipulationDelta"   
    ManipulationCompleted="lock_ManipulationCompleted" >

3.实现 lock_manipulationCompleted< /code>, lock_ManipulationDelta

 private void lock_ManipulationCompleted(object sender, ManipulationCompletedEventArgs  
  e)
    {
        if (this.gridTranslate.TranslateY< 0.0)
        {
            IEasingFunction function;
            this.CoastGrid.Stop();              
            this.gridTranslate.TranslateY = e.TotalManipulation.Translation.Y;              
            if((e.IsInertial)&& (e.FinalVelocities.LinearVelocity.Y<-1500)  ||
            (this.gridTranslate.TranslateY<(base.ActualHeight/-2.0)))
            {                 

                this.coastY.Value = (-1.0 * this.LockScreenGrid.ActualHeight);
                function = new CircleEase();                   
                ((CircleEase)function).Ease(1.0);                  
            }
            else
            {                 
                this.coastY.Value = 0.0;
                function = new BounceEase();                   
                ((BounceEase)function).Ease(0);                   
                ((BounceEase)function).Ease(2);                    
                ((BounceEase)function).Ease(5.0);
            }             
            this.coastY.EasingFunction=function;
            this.CoastGrid.Begin();
        }
    }
    private void lock_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
    {           
        e.Handled = true;         
        this.gridTranslate.TranslateY = (this.gridTranslate.TranslateY +   
        e.DeltaManipulation.Translation.Y);           
        if(this.gridTranslate.TranslateY>0.0)
        {               
            this.gridTranslate.TranslateY = 0.0;
        }
    }

These are the steps to achieve wp7 page unlock animation

1.Create the following storyboards

 <Storyboard x:Name="LockScreenSlideAnimation">
       <DoubleAnimation Duration="0:0:1" To="-768"  
       Storyboard.TargetProperty="  
       (UIElement.RenderTransform).  
       (CompositeTransform.TranslateY)" 
       Storyboard.TargetName="LockScreenGrid" d:IsOptimized="True"/>
 </Storyboard>

    <Storyboard x:Name="CoastGrid" >
 <DoubleAnimationUsingKeyFrames 
   Storyboard.TargetName="LockScreenGrid"                      

    Storyboard.TargetProperty="(UIElement.RenderTransform)
    .(CompositeTransform.TranslateY)">
                    <EasingDoubleKeyFrame x:Name="coastY"           
            KeyTime="00:00:01" Value="0">
                    </EasingDoubleKeyFrame>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>

2.Assume that the grid name is LockScreenGrid [Image Grid which will fly up on tap]

<Grid Grid.Row="1" x:Name="LockScreenGrid" Visibility="{Binding        

  LockScreenGridVisibility}"
   ManipulationDelta="lock_ManipulationDelta"   
    ManipulationCompleted="lock_ManipulationCompleted" >

3.Implement lock_manipulationCompleted, lock_ManipulationDelta

 private void lock_ManipulationCompleted(object sender, ManipulationCompletedEventArgs  
  e)
    {
        if (this.gridTranslate.TranslateY< 0.0)
        {
            IEasingFunction function;
            this.CoastGrid.Stop();              
            this.gridTranslate.TranslateY = e.TotalManipulation.Translation.Y;              
            if((e.IsInertial)&& (e.FinalVelocities.LinearVelocity.Y<-1500)  ||
            (this.gridTranslate.TranslateY<(base.ActualHeight/-2.0)))
            {                 

                this.coastY.Value = (-1.0 * this.LockScreenGrid.ActualHeight);
                function = new CircleEase();                   
                ((CircleEase)function).Ease(1.0);                  
            }
            else
            {                 
                this.coastY.Value = 0.0;
                function = new BounceEase();                   
                ((BounceEase)function).Ease(0);                   
                ((BounceEase)function).Ease(2);                    
                ((BounceEase)function).Ease(5.0);
            }             
            this.coastY.EasingFunction=function;
            this.CoastGrid.Begin();
        }
    }
    private void lock_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
    {           
        e.Handled = true;         
        this.gridTranslate.TranslateY = (this.gridTranslate.TranslateY +   
        e.DeltaManipulation.Translation.Y);           
        if(this.gridTranslate.TranslateY>0.0)
        {               
            this.gridTranslate.TranslateY = 0.0;
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文