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

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

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

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

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

比如函數

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

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

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

記住要認真玩,這樣你才會熟悉緩動函數與相關的類。

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

演練一

請參考以下XAML代碼構建你的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. }   

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

演練二:

參考以下XAML代碼創建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上右擊,從彈出的菜單中選擇“導航到事件處理程序”,在生成的方法中完成以下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 是包含所有頁面內容的根網格-->   
  16.         <Grid x:Name="LayoutRoot" Background="Transparent">   
  17.             <Grid.RowDefinitions>   
  18.                 <RowDefinition Height="Auto"/>   
  19.                 <RowDefinition Height="*"/>   
  20.             </Grid.RowDefinitions>   
  21.             <!--TitlePanel 包含應用程序的名稱和頁標題-->   
  22.             <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">   
  23.                 <TextBlock x:Name="ApplicationTitle" Text="我的應用程序" Style="{StaticResource PhoneTextNormalStyle}"/>   
  24.                 <TextBlock x:Name="PageTitle" Text="頁面名稱" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>   
  25.             </StackPanel>   
  26.             <!--ContentPanel - 在此處放置其他內容-->   
  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方法上右擊,從彈出的菜單中選擇“導航到事件處理程序”,完成后臺代碼邏輯。

  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. }   

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

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

 

責任編輯:閆佳明 來源: oschina
相關推薦

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技術棧公眾號

主站蜘蛛池模板: 日韩中文字幕 | 欧美成人精品二区三区99精品 | 精品日韩一区二区 | 成人伊人 | 亚洲成人www | 国产在视频一区二区三区吞精 | 99热首页 | 欧美一a| 麻豆精品国产91久久久久久 | 国内精品视频免费观看 | 羞视频在线观看 | 久久久久久久久久久久久9999 | 国产成人一区二区三区电影 | 一区二区三区日韩 | 久国产视频 | 久婷婷| 久草色视频| 亚洲精品一区在线 | 欧美成年网站 | 欧美成人猛片aaaaaaa | 99热这里 | 国产精品成人一区二区 | 99精品国产一区二区三区 | 成人精品一区二区三区 | 伊人国产精品 | 欧美一区二区大片 | 欧美日韩国产一区 | 国产一区二区在线观看视频 | 日韩高清在线 | 亚洲一区二区三区在线视频 | 天天躁日日躁狠狠很躁 | www.99热这里只有精品 | 91国语清晰打电话对白 | 中文字幕视频免费 | 国产精品精品久久久 | 中文字幕一区二区三区四区五区 | 日本久久视频 | 女人天堂av | 国产网站在线播放 | 久久久久国产精品 | 91天堂|