zoukankan      html  css  js  c++  java
  • Easing Animation(缓动动画)

     1 namespace Easing2
    2 {
    3
    4
    5 //EasingFunctionBase 为所有缓动函数提供基类
    6 class CustomPowerEase : EasingFunctionBase
    7 {
    8
    9 // Using a DependencyProperty as the backing store for Power.
    10 // This enables animation, styling, binding, etc...
    11
    12 // UIPropertyMetadata(object DefaultValue)用属性的指定默认值初始化 System.Windows.UIPropertyMetadata 类的新实例。
    13
    14 public static readonly DependencyProperty PowerProperty =
    15 DependencyProperty.Register("Power", typeof(double), typeof(CustomPowerEase), new UIPropertyMetadata(6.0));
    16
    17 //添加属性包装器
    18 public double Power
    19 {
    20 get { return (double)GetValue(PowerProperty); }
    21 set { SetValue(PowerProperty, value); }
    22 }
    23
    24 //System.Windows.Freezable, 定义一个对象,该对象具有可修改状态和只读(冻结)状态。
    25 //派生自 System.Windows.Freezable 的类提供详细的更改通知,可以是不可变的,并且可以进行自我克隆。
    26 protected override System.Windows.Freezable CreateInstanceCore()
    27 {
    28 return new CustomPowerEase();
    29 }
    30
    31 protected override double EaseInCore(double normalizedTime)
    32 {
    33 //Math.Pow(double x,double y)返回指定数字的指定次幂
    34 return Math.Pow(normalizedTime, Power);
    35 }
    36 }
    37 }
     XAML Code
     1 <Window x:Class="Easing2.MainWindow"
    2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    4 xmlns:local="clr-namespace:Easing2"
    5 Title="MainWindow" Height="350" Width="525">
    6
    7 <Window.Resources>
    8 <Storyboard x:Key="AnimateTarget">
    9 <!--Storyboard.TargetName,获取或设置要进行动画处理的对象的名称。
    10 Storyboard.TargetProperty,获取或设置应进行动画处理的属性。-->
    11
    12 <DoubleAnimationUsingKeyFrames Storyboard.TargetName="Transform" Storyboard.TargetProperty="X">
    13 <!--EasingDoubleKeyFrame类,通过它可以将缓动函数与 DoubleAnimationUsingKeyFrames 关键帧动画相关联-->
    14 <EasingDoubleKeyFrame KeyTime="0:0:0" Value="0.0">
    15 <!--EasingDoubleKeyFrame,Value获取或设置关键帧的目标值。-->
    16 </EasingDoubleKeyFrame>
    17
    18 <EasingDoubleKeyFrame KeyTime="0:0:4" Value="100.0">
    19 <!--EasingDoubleKeyFrame.EasingFunction获取或设置应用于关键帧的缓动函数。-->
    20 <EasingDoubleKeyFrame.EasingFunction>
    21 <!--这里使用了DP Power-->
    22 <local:CustomPowerEase Power="20" />
    23 </EasingDoubleKeyFrame.EasingFunction>
    24 </EasingDoubleKeyFrame>
    25
    26 </DoubleAnimationUsingKeyFrames>
    27
    28 <DoubleAnimationUsingKeyFrames Storyboard.TargetName="Transform" Storyboard.TargetProperty="Y">
    29
    30 <EasingDoubleKeyFrame KeyTime="0:0:0" Value="0.0">
    31 </EasingDoubleKeyFrame>
    32
    33 <EasingDoubleKeyFrame KeyTime="0:0:4" Value="100.0">
    34
    35 <EasingDoubleKeyFrame.EasingFunction>
    36
    37 <!--<PowerEase EasingMode="EaseIn" Power="5"/>-->
    38 <!--PowerEase.EaseInCore,此成员重写 EasingFunctionBase.EaseInCore(Double),
    39 提供缓动函数的逻辑部分,通过重写此部分可以生成自定义缓动函数的 EaseIn 模式。
    40 -->
    41 <local:CustomPowerEase Power="10" />
    42 </EasingDoubleKeyFrame.EasingFunction>
    43
    44 </EasingDoubleKeyFrame>
    45 </DoubleAnimationUsingKeyFrames>
    46
    47 </Storyboard>
    48 </Window.Resources>
    49
    50 <Grid>
    51 <Rectangle Width="20" Height="20" Fill="Red" RenderTransformOrigin="0.5, 0.5">
    52 <Rectangle.RenderTransform>
    53 <TranslateTransform x:Name="Transform" />
    54 </Rectangle.RenderTransform>
    55 </Rectangle>
    56
    57 <Button Width="100" Height="40" Content="Start Animation" Click="Button_Click"
    58 HorizontalAlignment="Center"
    59 VerticalAlignment="Bottom" />
    60 </Grid>
    61 </Window>
    1 private void Button_Click(object sender, RoutedEventArgs e)
    2 {
    3 ((Storyboard)this.Resources["AnimateTarget"]).Begin();
    4 }





  • 相关阅读:
    文件批量改名(有规律)
    js阻止事件冒泡(phpcms,浮窗第一次10秒弹出后每30秒弹出,动态更换日期)
    关于阿里云ECS Centos 5/6/7 Linux Glibc库严重安全漏洞修复方法
    js中div显示和隐藏钮为什么页面总是跳一下到最上面
    ssh 或 putty 连接linux报错解决方法
    phpcms v9编辑器上传图片是否添加水印
    Linux CURL的安装和使用
    phpcms v9全站点击量排行代码
    MySQL manager or server PID file could not be found!
    linux命令技巧
  • 原文地址:https://www.cnblogs.com/January/p/2434778.html
Copyright © 2011-2022 走看看