动画还是比较简单的,虽然写完一篇了,还是来继续WPF动画下一篇:缓动函数与触发器吧。
先讲讲缓动函数,在线性动画中,例如DoubleAnimation中,有一个属性就是EasingFunction,这个属性接收一个缓动函数类(注意是一个不能多个),在DoubleAnimation中,很多时候都能用,例如故事板,它的个体都是DoubleAnimationBase那个层面的类的,然而缓动函数是用在DoubleAnimatoinBase那个层面类中的,所以说用的也比较广的,其实使用是十分地方便的,多数都在Xaml中的字典上配合DoubleAnimationBase这个层面上的子类来使用的,学的话就学各个缓动函数的特点和用处:
先给出一个例子了解一下:
<Storyboard x:Key="UsingBackEaseAnimation">
<DecimalAnimation To="100" Duration="0:0:2" AutoReverse="True" Storyboard.TargetProperty="Vidth" Storyboard.TargetName="button">
<DecimalAnimation.EasingFunction><!--这个是拉回缓动函数-->
<BackEase EasingMode="EaseInOut" Amplitude="2"></BackEase>
</DecimalAnimation.EasingFunction>
</DecimalAnimation>
</Storyboard>
换其他一样用的。下面分别介绍各种缓动函数以及各个缓动函数的特征:
在跳舞的时候也有一个叫Animation的元素,很多都是通的,先快后匀速啊,先慢后快啊,先满后匀速啊,速度呈指数增长啊,呈园增长啊,呈3次方增长啊,气球的弹跳效果啊,橡皮筋的拉回效果啊,都是缓动。这样一说好像差不多说完了,下面统一说一下,首先说一下缓动函数类的一些主要属性:EaseIn(在进来的时候缓动),EaseOut(在出去的时候缓动),EaseInOut(进来和出去都缓动),简单明了。
1.BackEase缓动函数,实现拉回效果。设置Amplitude来设置拉伸幅度和力度等
<Storyboard x:Key="UsingBackEaseAnimation">
<DoubleAnimation To="45" Duration="0:0:3">
<DoubleAnimation.EasingFunction>
<!--这个是拉回缓动函数-->
<BackEase EasingMode="EaseInOut" Amplitude="2"></BackEase>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
2.ElasticEase缓动函数,实现振荡效果,设置Oscillations来设置振荡次数(默认3),设置Springiness来设置振荡速度(默认也是3)
<Storyboard x:Key="UsingElasticEaseAnimation">
<!--这个是振荡缓动函数-->
<DoubleAnimation To="100" Duration="0:0:3" Storyboard.TargetProperty="Height" Storyboard.TargetName="button">
<DoubleAnimation.EasingFunction>
<ElasticEase EasingMode="EaseInOut" Oscillations="3" Springiness="3"></ElasticEase>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
3.CircleEae缓动函数,使用圆函数加速或者减速动画的运行,没有属性要设置。
<Storyboard x:Key="UsingCircleEaseAnimation">
<!--使用圆函数加速或减速动画-->
<DoubleAnimation To="100" Duration="0:0:2" Storyboard.TargetProperty="(Canvas.Left)" Storyboard.TargetName="button">
<DoubleAnimation.EasingFunction>
<CircleEase EasingMode="EaseInOut"></CircleEase>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>