自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Windows Phone開發(fā)(40):漫談關(guān)鍵幀動(dòng)畫中篇

移動(dòng)開發(fā)
盡管前面介紹的幾種動(dòng)畫會(huì)讓覺得很好玩了,但是,不知道你是否發(fā)現(xiàn),在前面說到的一系列XXXAnimation中,都有一個(gè)共同點(diǎn),那就是僅僅針對兩個(gè)值的目標(biāo)值之間產(chǎn)生動(dòng)畫,如果使用By,將在原值和加上By后的目標(biāo)值之間進(jìn)行動(dòng)畫處理;如果使用From,To,那就更好理解了,就是首尾兩個(gè)值之間值的動(dòng)畫。

一、DiscreteDoubleKeyFrame

離散型關(guān)鍵幀動(dòng)畫,重點(diǎn),我們理解一下“離散”的意思,其實(shí)你查一下《新華字典》,“離”和“散”的意思相近。我們可以這樣解釋:每個(gè)關(guān)鍵幀之間是直接過渡,其間不經(jīng)過動(dòng)畫插補(bǔ)。似乎這樣理解有點(diǎn)苦澀難懂,所以,我們還是從實(shí)例入手。

請參考以下XAML代碼寫一個(gè)示例:

  1.     <Grid Loaded="OnGridLoaded">   
  2.         <Rectangle Width="100" Height="100" Fill="Green" VerticalAlignment="Top">   
  3.             <Rectangle.RenderTransform>   
  4.                 <TranslateTransform x:Name="trm"/>   
  5.             </Rectangle.RenderTransform>   
  6.         </Rectangle>   
  7.         <Grid.Resources>   
  8.             <Storyboard x:Name="std">   
  9.                 <DoubleAnimationUsingKeyFrames Duration="0:0:5" RepeatBehavior="15"   
  10. Storyboard.TargetName="trm"   
  11. Storyboard.TargetProperty="Y">   
  12.                     <DiscreteDoubleKeyFrame KeyTime="0:0:2" Value="150"/>   
  13.                     <DiscreteDoubleKeyFrame KeyTime="0:0:3" Value="280"/>   
  14.                     <DiscreteDoubleKeyFrame KeyTime="0:0:5" Value="380"/>   
  15.                 </DoubleAnimationUsingKeyFrames>   
  16.             </Storyboard>   
  17.         </Grid.Resources>   
  18.     </Grid>   

在后臺(tái)的C#代碼中,千萬不要記了啟動(dòng)動(dòng)畫,等下運(yùn)行后發(fā)現(xiàn)動(dòng)不了就麻煩了。

  1. private void OnGridLoaded(object sender, RoutedEventArgs e)   
  2. {   
  3.     this.std.Begin();   
  4. }   

然后你可以運(yùn)行了,注意認(rèn)真觀察動(dòng)畫的演變過程。

不知道你觀察到了什么?你是否發(fā)現(xiàn),矩形向下運(yùn)動(dòng)的過程是直接跳躍式的,每個(gè)關(guān)鍵之間沒有創(chuàng)建過渡效果,而且直接跳到對應(yīng)值。

二、DiscreteColorKeyFrame

這也是一個(gè)離散型關(guān)鍵幀動(dòng)畫,從名字上我們知道,它是針對顏色進(jìn)行動(dòng)畫處理的。還是看例子吧。

請參考下面XAML代碼寫一個(gè)測試程序:

  1.     <Grid Loaded="OnGridLoaded">   
  2.         <Ellipse Width="250" Height="250">   
  3.             <Ellipse.Fill>   
  4.                 <SolidColorBrush x:Name="brush" Color="Blue"/>   
  5.             </Ellipse.Fill>   
  6.         </Ellipse>   
  7.         <Grid.Resources>   
  8.             <Storyboard x:Name="std">   
  9.                 <ColorAnimationUsingKeyFrames Duration="0:0:8"   
  10. RepeatBehavior="20"   
  11. Storyboard.TargetName="brush"   
  12. Storyboard.TargetProperty="Color">   
  13.                     <DiscreteColorKeyFrame KeyTime="0:0:2" Value="Yellow"/>   
  14.                     <DiscreteColorKeyFrame KeyTime="0:0:5" Value="Gray"/>   
  15.                     <DiscreteColorKeyFrame KeyTime="0:0:7" Value="Red"/>   
  16.                 </ColorAnimationUsingKeyFrames>   
  17.             </Storyboard>   
  18.         </Grid.Resources>   
  19.     </Grid>   

后臺(tái)代碼就不帖了,都懂得寫什么了。

然后運(yùn)行一下,查看效果。

從效果中可以看到,顏色的改變是沒有平滑的過渡效果的,而是當(dāng)時(shí)間線的播放時(shí)間到了關(guān)鍵幀所在的位置時(shí),顏色是直接改變的。

三、LinearColorKeyFrame

線性顏色的關(guān)鍵幀與離散型動(dòng)畫相反,每個(gè)關(guān)鍵幀之間都創(chuàng)建平滑的過渡效果,讓人看起來有連續(xù)感。

請參考以下XAML代碼寫一個(gè)測試程序。

  1.     <Grid Loaded="onGridLoaded">   
  2.         <Ellipse Width="300" Height="300" >   
  3.             <Ellipse.Fill>   
  4.                 <RadialGradientBrush x:Name="rdGradientBrush" Center="0.5, 0.5"   
  5.                                      RadiusX="0.5" RadiusY="0.5">   
  6.                     <GradientStop Color="LightGreen" Offset="0"/>   
  7.                     <GradientStop Color="DarkGreen" Offset="1"/>   
  8.                 </RadialGradientBrush>   
  9.             </Ellipse.Fill>   
  10.         </Ellipse>   
  11.         <Grid.Resources>   
  12.             <Storyboard x:Name="std">   
  13.                 <ColorAnimationUsingKeyFrames Duration="0:0:6"   
  14. RepeatBehavior="Forever"   
  15. Storyboard.TargetName="rdGradientBrush"   
  16. Storyboard.TargetProperty="(RadialGradientBrush.GradientStops)[0].(GradientStop.Color)">   
  17.                     <LinearColorKeyFrame KeyTime="0:0:1" Value="Orange"/>   
  18.                     <LinearColorKeyFrame KeyTime="0:0:3" Value="White"/>   
  19.                     <LinearColorKeyFrame KeyTime="0:0:6" Value="Pink"/>   
  20.                 </ColorAnimationUsingKeyFrames>   
  21.                 <ColorAnimationUsingKeyFrames Duration="0:0:6"   
  22. RepeatBehavior="Forever"   
  23. Storyboard.TargetName="rdGradientBrush"   
  24. Storyboard.TargetProperty="(RadialGradientBrush.GradientStops)[1].(GradientStop.Color)">   
  25.                     <LinearColorKeyFrame KeyTime="0:0:3" Value="Yellow"/>   
  26.                     <LinearColorKeyFrame KeyTime="0:0:6" Value="Violet"/>   
  27.                     <LinearColorKeyFrame KeyTime="0:0:7" Value="SeaGreen"/>   
  28.                 </ColorAnimationUsingKeyFrames>   
  29.             </Storyboard>   
  30.         </Grid.Resources>   
  31.     </Grid>   

頁面上的正圓是使用徑向漸變填充的,漸變顏色點(diǎn)有兩個(gè),我們分別對這兩個(gè)漸變點(diǎn)的顏色進(jìn)行線性動(dòng)畫處理,這樣就會(huì)做出很漂亮的效果,如下面圖片所示。

 

責(zé)任編輯:閆佳明 來源: oschina
相關(guān)推薦

2013-04-24 15:28:02

Windows PhoWindows Pho

2013-04-24 13:51:48

Windows PhoWindows Pho

2013-04-25 11:25:38

Windows PhoWindows Pho

2013-04-24 13:19:06

Windows Pho動(dòng)畫DoubleAni

2013-04-24 13:31:59

Windows Pho動(dòng)畫之ColorAni

2013-04-24 13:43:10

Windows Pho動(dòng)畫PointAnim

2018-09-21 15:26:45

大數(shù)據(jù)管理系統(tǒng)

2013-07-30 12:37:56

Windows PhoWindows Pho

2010-04-21 17:07:54

Windows Pho

2011-06-07 12:42:15

Windows Pho

2013-04-17 14:00:06

Windows PhoWindows Pho

2013-04-16 17:02:50

Windows Pho概論

2013-04-19 16:34:56

Windows PhoWindows Pho

2013-07-30 11:18:37

Windows PhoWindows Pho

2013-06-18 00:58:54

CocoStudio工Cocos2d-x

2023-06-16 09:45:36

AI視頻

2010-04-08 17:40:23

Windows Pho

2023-10-08 20:32:59

CSS定義Loading

2013-04-17 13:27:04

Windows PhoWindows Pho

2011-06-07 11:35:38

Windows Pho
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)