成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Windows Phone開發(fā)(42):緩動動畫

移動開發(fā)
我們看出來了,緩動函數(shù)涉及復(fù)雜的數(shù)學(xué)運算,不過,灰常幸運的是,常用的緩函數(shù)MS已經(jīng)為我們封裝好了,這也是從 WPF/Silverlight中遷移到WP的,集成性兼容性MD的好,所以,在使用的時候,大家可以輕松一大把了,因此,當(dāng)你在練習(xí)的時候,記得沖一杯 咖啡放在桌上,一邊寫代碼一邊品嘗吧。呵呵,編程快樂,快樂編程。

前面在討論關(guān)鍵幀動畫的時候,我有意把幾個帶緩動動畫的關(guān)鍵幀動畫忽略掉,如EasingColorKeyFrame、 EasingDoubleKeyFrame和EasingPointKeyFrame,其實為數(shù)不多,就這么幾個。因為我希統(tǒng)一放到這節(jié)課程來吹一下緩動 函數(shù)。

所謂緩動函數(shù),就是我們在代數(shù)里面說的函數(shù),說白了嘛,就是根特定的函數(shù)規(guī)則,用輸入的值算出最終值,使得動畫在兩個關(guān)鍵幀之間不再是均衡過度,而是帶有加/減速或其他效果,當(dāng)然,還要取決于算法。

比如函數(shù)

所以,我們看出來了,緩動函數(shù)涉及復(fù)雜的數(shù)學(xué)運算,不過,灰常幸運的是,常用的緩函數(shù)MS已經(jīng)為我們封裝好了,這也是從 WPF/Silverlight中遷移到WP的,集成性兼容性MD的好,所以,在使用的時候,大家可以輕松一大把了,因此,當(dāng)你在練習(xí)的時候,記得沖一杯 咖啡放在桌上,一邊寫代碼一邊品嘗吧。呵呵,編程快樂,快樂編程。

如果你干過WPF或SL,這些東西你會覺得灰常Easy,我不是第一次強調(diào)了,所以說,基礎(chǔ)很重要,把基礎(chǔ)扎實了,無論你學(xué)習(xí)什么新玩意兒,都可以一通百通的,不管你信不信,反正我信了。

如何你對緩動函數(shù)沒有一個直觀的認(rèn)識也不要緊,下面推薦大家一個游戲,很好玩的,不玩你學(xué)WP會后悔的。游戲地址:http://samples.msdn.microsoft.com/Silverlight/silverlight_next/Animations/easing_functions_gallery/testpage.html

記住要認(rèn)真玩,這樣你才會熟悉緩動函數(shù)與相關(guān)的類。

某致理名言說得好,“自己動手,豐衣足食”,還是老規(guī)矩,實例決定一切,動手干活吧。

演練一

請參考以下XAML代碼構(gòu)建你的UI。

  1.     <Grid Loaded="gridLoaded">   
  2.         <Ellipse HorizontalAlignment="Left"   
  3.                  VerticalAlignment="Top"   
  4.                  Fill="Orange"   
  5.                  Width="100"   
  6.                  Height="100"   
  7.                  x:Name="elp">   
  8.             <Ellipse.RenderTransform>   
  9.                 <TranslateTransform x:Name="trm"/>   
  10.             </Ellipse.RenderTransform>   
  11.         </Ellipse>   
  12.         <Grid.Resources>   
  13.             <Storyboard x:Name="std">   
  14.                 <DoubleAnimationUsingKeyFrames Duration="0:0:8"   
  15. Storyboard.TargetName="trm"   
  16. Storyboard.TargetProperty="Y"   
  17. RepeatBehavior="30">   
  18.                     <LinearDoubleKeyFrame KeyTime="0:0:0" Value="0"/>   
  19.                     <EasingDoubleKeyFrame KeyTime="0:0:8" Value="485">   
  20.                         <EasingDoubleKeyFrame.EasingFunction>   
  21.                             <BounceEase Bounciness="3" Bounces="3"/>   
  22.                         </EasingDoubleKeyFrame.EasingFunction>   
  23.                     </EasingDoubleKeyFrame>   
  24.                 </DoubleAnimationUsingKeyFrames>   
  25.             </Storyboard>   
  26.         </Grid.Resources>   
  27.     </Grid>   

后臺C#代碼啟用動畫。

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

現(xiàn)在,運行上面的示例,你會發(fā)現(xiàn)圓在下落的過程發(fā)生了兩次回彈,動畫才結(jié)束,而且一開始較慢,后來漸漸加速,這就是緩動函數(shù)所產(chǎn)生的效果。

演練二:

參考以下XAML代碼創(chuàng)建UI界面。

  1.     <Grid Loaded="gridLoaded">   
  2.         <Rectangle Margin="35" x:Name="rec">   
  3.             <Rectangle.Fill>   
  4.                 <LinearGradientBrush x:Name="brs" StartPoint="0,0.5" EndPoint="1,0.5">   
  5.                     <GradientStop Color="Blue" Offset="0"/>   
  6.                     <GradientStop Color="Yellow" Offset="0.5"/>   
  7.                     <GradientStop Color="Blue" Offset="1"/>   
  8.                 </LinearGradientBrush>   
  9.             </Rectangle.Fill>   
  10.         </Rectangle>   
  11.         <Grid.Resources>   
  12.             <Storyboard x:Name="std">   
  13.                 <DoubleAnimationUsingKeyFrames Duration="0:0:10"   
  14. Storyboard.TargetName="brs"   
  15. Storyboard.TargetProperty="(LinearGradientBrush.GradientStops)[1].(GradientStop.Offset)"   
  16. RepeatBehavior="35"   
  17. AutoReverse="True">   
  18.                     <EasingDoubleKeyFrame KeyTime="0:0:0" Value="0.2"/>   
  19.                     <EasingDoubleKeyFrame KeyTime="0:0:10" Value="0.8">   
  20.                         <EasingDoubleKeyFrame.EasingFunction>   
  21.                             <ElasticEase Oscillations="4" Springiness="1"/>   
  22.                         </EasingDoubleKeyFrame.EasingFunction>   
  23.                     </EasingDoubleKeyFrame>   
  24.                 </DoubleAnimationUsingKeyFrames>   
  25.             </Storyboard>   
  26.         </Grid.Resources>   
  27.     </Grid>   

在gridLoaded上右擊,從彈出的菜單中選擇“導(dǎo)航到事件處理程序”,在生成的方法中完成以下C#代碼。

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

運行程序后,你會看到漸變填充中間黃色的色塊在左右來回移動。

演練三:

請參照以下XAML建立UI。

  1.     <phone:PhoneApplicationPage    
  2.         x:Class="Sample.Page3"   
  3.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
  4.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
  5.         xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"   
  6.         xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"   
  7.         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"   
  8.         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
  9.         FontFamily="{StaticResource PhoneFontFamilyNormal}"   
  10.         FontSize="{StaticResource PhoneFontSizeNormal}"   
  11.         Foreground="{StaticResource PhoneForegroundBrush}"   
  12.         SupportedOrientations="Portrait" Orientation="Portrait"   
  13.         mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"   
  14.         shell:SystemTray.IsVisible="True">   
  15.         <!--LayoutRoot 是包含所有頁面內(nèi)容的根網(wǎng)格-->   
  16.         <Grid x:Name="LayoutRoot" Background="Transparent">   
  17.             <Grid.RowDefinitions>   
  18.                 <RowDefinition Height="Auto"/>   
  19.                 <RowDefinition Height="*"/>   
  20.             </Grid.RowDefinitions>   
  21.             <!--TitlePanel 包含應(yīng)用程序的名稱和頁標(biāo)題-->   
  22.             <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">   
  23.                 <TextBlock x:Name="ApplicationTitle" Text="我的應(yīng)用程序" Style="{StaticResource PhoneTextNormalStyle}"/>   
  24.                 <TextBlock x:Name="PageTitle" Text="頁面名稱" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>   
  25.             </StackPanel>   
  26.             <!--ContentPanel - 在此處放置其他內(nèi)容-->   
  27.             <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">   
  28.                 <Rectangle HorizontalAlignment="Left" VerticalAlignment="Bottom"   
  29.                            Width="60" Height="45" Fill="White"   
  30.                            MouseLeftButtonDown="onShow"/>   
  31.                 <TextBlock HorizontalAlignment="Center"   
  32.                            VerticalAlignment="Center"   
  33.                            Text="請點擊左下角的白色矩形。"   
  34.                            TextWrapping="Wrap"   
  35.                            Margin="30,0,40,0"   
  36.                            FontSize="45"/>   
  37.                 <StackPanel x:Name="sp" Background="LightBlue"   
  38.                             Height="180"   
  39.                             VerticalAlignment="Bottom">   
  40.                     <TextBlock Foreground="Red"    
  41.                                Margin="20,22,20,20"   
  42.                                FontSize="32"   
  43.                                Text="你好,點擊下面的按鈕吧。"/>   
  44.                     <Button Content="確    定" Background="Blue"   
  45.                             Click="onHide"/>   
  46.                     <StackPanel.RenderTransform>   
  47.                         <TranslateTransform x:Name="trm"   
  48.                                             Y="180"/>   
  49.                     </StackPanel.RenderTransform>   
  50.                 </StackPanel>   
  51.  
  52.                 <Grid.Resources>   
  53.                     <Storyboard x:Name="stdShow">   
  54.                         <DoubleAnimationUsingKeyFrames   
  55.                             Storyboard.TargetName="trm"   
  56.                             Storyboard.TargetProperty="Y"   
  57.                             Duration="1">   
  58.                             <EasingDoubleKeyFrame   
  59.                                 KeyTime="0:0:0" Value="180"/>   
  60.                             <EasingDoubleKeyFrame   
  61.                                 KeyTime="0:0:1" Value="0">   
  62. <EasingDoubleKeyFrame.EasingFunction>   
  63.                                     <PowerEase Power="10"/>   
  64. </EasingDoubleKeyFrame.EasingFunction>   
  65.                             </EasingDoubleKeyFrame>   
  66.                         </DoubleAnimationUsingKeyFrames>   
  67.                     </Storyboard>   
  68.                     <Storyboard x:Name="stdHide">   
  69.                         <DoubleAnimationUsingKeyFrames   
  70.                             Duration="0:0:1"   
  71.                             Storyboard.TargetName="trm"   
  72.                             Storyboard.TargetProperty="Y">   
  73.                             <EasingDoubleKeyFrame KeyTime="0:0:0"   
  74.                                                   Value="0"/>   
  75.                             <EasingDoubleKeyFrame KeyTime="0:0:1"   
  76.                                                   Value="180">   
  77. <EasingDoubleKeyFrame.EasingFunction>   
  78.                                     <PowerEase Power="10"/>   
  79. </EasingDoubleKeyFrame.EasingFunction>   
  80.                             </EasingDoubleKeyFrame>   
  81.                         </DoubleAnimationUsingKeyFrames>   
  82.                     </Storyboard>   
  83.                 </Grid.Resources>   
  84.             </Grid>   
  85.         </Grid>   
  86.     </phone:PhoneApplicationPage>   

分別在onShow和onHide方法上右擊,從彈出的菜單中選擇“導(dǎo)航到事件處理程序”,完成后臺代碼邏輯。

  1. private void onShow(object sender, MouseButtonEventArgs e)   
  2. {   
  3.     if (stdHide.GetCurrentState() != ClockState.Stopped)   
  4.     {   
  5.         stdHide.Stop();   
  6.     }   
  7.     stdShow.Begin();   
  8. }  
  9. private void onHide(object sender, RoutedEventArgs e)   
  10. {   
  11.     if (stdShow.GetCurrentState() != ClockState.Stopped)   
  12.     {   
  13.         stdShow.Stop();   
  14.     }   
  15.     stdHide.Begin();   
  16. }   

現(xiàn)在,運行程序,單擊屏幕左下方的白色矩形,這時候屏幕下方會彈出一個面板,再點擊面板上的按鈕,面板會縮下去。

這樣,使用動畫,我們就做出了一個類似工具條的效果。

 

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

2013-04-24 13:31:59

Windows Pho動畫之ColorAni

2013-04-24 13:19:06

Windows Pho動畫DoubleAni

2013-04-24 13:43:10

Windows Pho動畫PointAnim

2013-07-30 12:37:56

Windows PhoWindows Pho

2010-04-21 17:07:54

Windows Pho

2013-04-24 13:51:48

Windows PhoWindows Pho

2013-04-24 14:52:53

Windows PhoWindows Pho

2013-04-24 15:28:02

Windows PhoWindows Pho

2013-04-17 14:00:06

Windows PhoWindows Pho

2011-06-07 12:42:15

Windows 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

2010-04-08 17:40:23

Windows Pho

2021-01-31 17:34:01

Windows 10Windows微軟

2009-02-23 09:19:33

windows 7啟動畫面

2010-07-16 15:29:02

Windows Pho

2012-08-16 10:35:50

Windows Pho

2011-06-07 11:35:38

Windows Pho

2013-04-17 13:27:04

Windows PhoWindows Pho
點贊
收藏

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

主站蜘蛛池模板: 夜夜爽99久久国产综合精品女不卡 | 中文字幕第九页 | 欧美日韩亚洲视频 | 欧美一级欧美三级在线观看 | 羞羞视频免费在线观看 | 999热精品视频 | 国产欧美一区二区三区在线看蜜臀 | 久久亚洲国产精品日日av夜夜 | 黄色大片在线免费观看 | 精品乱子伦一区二区三区 | 久久久久久99 | 欧美男人天堂 | 色婷婷综合久久久中字幕精品久久 | 国产女人与拘做视频免费 | 国产成人麻豆免费观看 | 国产一级黄色网 | 中文字幕成人 | www.色综合 | 雨宫琴音一区二区在线 | 久久久激情视频 | 亚洲精品久久久久久久久久吃药 | 色www精品视频在线观看 | 特级一级黄色片 | 亚洲欧洲一区二区 | 浮生影院免费观看中文版 | 中文字幕一二三区 | 精品免费 | 一区二区三区网站 | 97人人超碰 | 日本一区二区三区四区 | 中文字幕在线观看一区二区 | 一区二区三区免费在线观看 | 涩爱av一区二区三区 | 国产一区二区中文字幕 | 成人国产免费视频 | 天天精品在线 | 91精品久久久久 | 国产精品无码久久久久 | 午夜99 | 日韩一区二区在线观看 | 久草视频在线播放 |