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 }





  • 相关阅读:
    linux下shell显示-bash-4.1#不显示路径解决方法
    update chnroute
    An error "Host key verification failed" when you connect to other computer by OSX SSH
    使用dig查询dns解析
    DNS被污染后
    TunnelBroker for EdgeRouter 后记
    mdadm详细使用手册
    关于尼康黄的原因
    Panda3d code in github
    Python实例浅谈之三Python与C/C++相互调用
  • 原文地址:https://www.cnblogs.com/January/p/2434778.html
Copyright © 2011-2022 走看看