最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于WPF繪制一個(gè)點(diǎn)贊大拇指動(dòng)畫

 更新時(shí)間:2023年02月13日 08:37:13   作者:ARM830  
這篇文章主要為大家詳細(xì)介紹了WPF實(shí)現(xiàn)繪制一個(gè)點(diǎn)贊大拇指動(dòng)畫,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)或工作有一定幫助,感興趣的小伙伴可以了解一下

效果圖

好久沒有寫wpf了。

最近看到飛書的點(diǎn)贊動(dòng)畫非常有意思,決定試試,雖然不及飛書那樣的絢麗,但是練手還是可以的,希望自己的手藝還在!

實(shí)現(xiàn)思路

那么如何寫一個(gè)這樣的動(dòng)畫呢?

首先需要刨析這個(gè)動(dòng)畫的構(gòu)成:

  • 外圈圓
  • 大拇指-1豎著
  • 大拇指-2握著
  • 顫動(dòng)動(dòng)畫
  • 中心旋轉(zhuǎn)動(dòng)畫
  • 展開中心旋轉(zhuǎn)動(dòng)畫

當(dāng)我們分析這些東西剩下的就好辦了。

首先我們先辦了這個(gè)最難的東西大拇指。

 這個(gè)東西的構(gòu)成,我們使用Path 直接去寫。顯然我們就會(huì)得到這樣的代碼

<Geometry  x:Key="t1">
            M 20 40
                v 0 40
                h 0 7
                v 0 -40
                z
                M 30 42
                v 0  38
                h 40 0
                l 15 -35
                l -10 -5
                h -25 0 
                l 2 -20
            <!--小褶皺-->
            q -10 -10, -20 22
               z
  </Geometry>

當(dāng)我們?cè)趐ath 100*100的大小的時(shí)候使用腦補(bǔ)進(jìn)行繪制就就可以了。

至于這個(gè)小褶皺我曾經(jīng)不想要,但是看到了自己的豬爪...還是決定加上了。

這代碼的原理非常簡(jiǎn)單,基本都是基本的直線繪制,最難的就是用了個(gè)貝塞爾來(lái)制造大拇指背部的弧度.

不管咋樣還是弄出來(lái)個(gè)簡(jiǎn)單的贊。

剩下就是握著的狀態(tài)了

那么我們只需要修改部分代碼就可以達(dá)到了~

也就是

<Geometry  x:Key="t2">
            M 20 40
                v 0 40
                h 0 7
                v 0 -40
                z
                M 30 42
                v 0  38
                h 40 0
                l 15 -35
                l -10 -5
                h -25 0 
                l 2  0
            <!--小褶皺-->
            q -10 -10, -20 0
                z
        </Geometry>

我們修改了最后兩行代碼的 l 的y參數(shù)和q最后的end point參數(shù)的y的值都是降到0了 這樣會(huì)形成一個(gè)簡(jiǎn)單的弧度

哈 這樣子 我們就是得到了兩個(gè)手掌的不同狀態(tài)了。

剩下的事情就是來(lái)組裝吧~~~~

首先是大拇指張開和大拇指握住的狀態(tài)轉(zhuǎn)換。

做到這事情最簡(jiǎn)單的動(dòng)畫就是使用eventtigger來(lái)做,我們使用簡(jiǎn)單的鼠標(biāo)按下事件作為啟動(dòng),當(dāng)然了 想要豐富過程也是可以使用鼠標(biāo)浮動(dòng)事件作為啟動(dòng)事件之一。

<Path.Triggers>
                    <EventTrigger  RoutedEvent="MouseLeftButtonDown">
                        <BeginStoryboard x:Name="Bs1">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetProperty="Data">
                                    <DiscreteObjectKeyFrame KeyTime="0:0:0.01">
                                        <DiscreteObjectKeyFrame.Value>
                                            <StaticResource ResourceKey="t2"/>
                                        </DiscreteObjectKeyFrame.Value>
                                    </DiscreteObjectKeyFrame>
                                </ObjectAnimationUsingKeyFrames>
                 </Storyboard>
                        </BeginStoryboard>
             </EventTrigger>
                </Path.Triggers>

為了做件事 ,我們把geometry作為window的資源 所以子啊寫動(dòng)畫的時(shí)候 用離弦值就非常方便了。

觀察代碼,我們僅僅只是在點(diǎn)下的時(shí)候讓path轉(zhuǎn)換為握住的data,因?yàn)槲覀冃枰谒砷_左鍵的時(shí)候才讓拇指豎起來(lái)。

所以還需要補(bǔ)上一個(gè)MouseLeftButtonUp的動(dòng)畫

這最終的代碼就是

<Path.Triggers>
                    <EventTrigger  RoutedEvent="MouseLeftButtonDown">
                        <BeginStoryboard x:Name="Bs1">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetProperty="Data">
                                    <DiscreteObjectKeyFrame KeyTime="0:0:0.01">
                                        <DiscreteObjectKeyFrame.Value>
                                            <StaticResource ResourceKey="t2"/>
                                        </DiscreteObjectKeyFrame.Value>
                                    </DiscreteObjectKeyFrame>
                                </ObjectAnimationUsingKeyFrames>
                 </Storyboard>
                        </BeginStoryboard>
             </EventTrigger>
             <EventTrigger RoutedEvent="MouseLeftButtonUp">
                        <RemoveStoryboard BeginStoryboardName="Bs1"/>
                    </EventTrigger>
                </Path.Triggers>

效果圖

莫名的搞笑....

基礎(chǔ)的東西我們構(gòu)建好了,剩下就是補(bǔ)全了。

不全顫抖啊,補(bǔ)全中心旋轉(zhuǎn)動(dòng)畫,也就是手指握住后有一個(gè)向下的動(dòng)畫。

首先這個(gè)顫動(dòng) 我們可以簡(jiǎn)單的理解為位移,一個(gè)快速的上下左右的位移

正好WPF有這種動(dòng)畫 所以我們就可以得到如下的代碼

<ThicknessAnimationUsingKeyFrames RepeatBehavior="Forever" Duration="0:0:0.4"  Storyboard.TargetProperty="Margin" >
                                    <SplineThicknessKeyFrame KeyTime="0:0:0.0" Value="4,3,0,0"/>
                                    <SplineThicknessKeyFrame KeyTime="0:0:0.2" Value="3,4,0,0"/>
                                    <SplineThicknessKeyFrame KeyTime="0:0:0.3" Value="0,0,4,0"/>
                                    <SplineThicknessKeyFrame KeyTime="0:0:0.35" Value="0,0,4,3"/>
                                    <SplineThicknessKeyFrame KeyTime="0:0:0.4" Value="4,3,0,0"/>
                                </ThicknessAnimationUsingKeyFrames>

我們可以直代碼放到path的eventtriger中

看得出來(lái) 離散動(dòng)畫的值就是簡(jiǎn)單的marigin的位移,代碼非常簡(jiǎn)單。

就是在這里顫抖...

雖然看上去不是很好看,但是我們結(jié)合下一個(gè)動(dòng)畫,也就是手掌向下就會(huì)好很多了

這個(gè)動(dòng)畫很明顯是一個(gè)旋轉(zhuǎn)動(dòng)畫,所以我們需要提前準(zhǔn)備一個(gè)roteate的transofrom

代碼如下

<Path.RenderTransform>
                    <RotateTransform x:Name="rote" Angle="0"/>
  </Path.RenderTransform>

動(dòng)畫代碼如下

<DoubleAnimation   Duration="0:0:0.1" To="30" Storyboard.TargetName="rote" Storyboard.TargetProperty="Angle">
                                    <DoubleAnimation.EasingFunction>
                                        <CubicEase/>
                                    </DoubleAnimation.EasingFunction>
       </DoubleAnimation>

我們簡(jiǎn)單的使用了一個(gè)函數(shù),提升一下效果的動(dòng)感...

但是感覺沒啥用

效果圖就是這樣的了

雖然看上去已經(jīng)非常不錯(cuò)了,但是還有些不做,想想 我們的手都朝下了 松開之后為啥沒有一個(gè)向上的彈簧動(dòng)作呢?

也就是我們需要在抬起時(shí)加上一個(gè)角度的旋轉(zhuǎn)。

<EventTrigger RoutedEvent="MouseLeftButtonUp">
                        <BeginStoryboard x:Name="Bs2">
                            <Storyboard>
                                <DoubleAnimation  FillBehavior="Stop"  Duration="0:0:0.5" To="-30" Storyboard.TargetName="rote" Storyboard.TargetProperty="Angle">
                                    <DoubleAnimation.EasingFunction>
                                        <CubicEase EasingMode="EaseOut"/>
                                    </DoubleAnimation.EasingFunction>
                                </DoubleAnimation>
                            </Storyboard>
                        </BeginStoryboard>
                        <RemoveStoryboard BeginStoryboardName="Bs1"/>
                    </EventTrigger>

代碼可以說手掌向下的反向操作。

順便播放完把bs1動(dòng)畫解除掉。

剩下的就是圈的構(gòu)造和動(dòng)畫。

圓圈呢,我們可以是直接的圓圈,也可以是broder,看個(gè)人喜歡了。

我就不羅嗦直接上代碼

<Border  BorderThickness="2" Background="Transparent" BorderBrush="Transparent"   CornerRadius="100" Width="200" Height="{Binding  RelativeSource={RelativeSource Mode=Self}, Path=Width}" Grid.Column="1" Grid.Row="1">
            <Border x:Name="sor" Visibility="Hidden" BorderThickness="2" Background="Transparent" BorderBrush="Transparent"   CornerRadius="100" Width="200" Height="{Binding  RelativeSource={RelativeSource Mode=Self}, Path=Width}" Grid.Column="1" Grid.Row="1"/>
        </Border>

構(gòu)造了兩個(gè)嵌套的borderr,寬度其實(shí)可以隨意,只是演示的時(shí)候放大的大小而已。

動(dòng)畫則是放到了path的啟動(dòng)動(dòng)畫之中

也就是

<DoubleAnimation RepeatBehavior="Forever" SpeedRatio="1.2" Duration="0:0:1.5" To="0" Storyboard.TargetName="sor" Storyboard.TargetProperty="Width">
                                    <DoubleAnimation.EasingFunction>
                                        <CubicEase/>
                                    </DoubleAnimation.EasingFunction>
                                </DoubleAnimation>
                                <ObjectAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetName="sor" Storyboard.TargetProperty="Visibility">
                                    <DiscreteObjectKeyFrame KeyTime="0:0:0.1">
                                        <DiscreteObjectKeyFrame.Value>
                                            <Visibility>
                                                Visible
                                            </Visibility>
                                        </DiscreteObjectKeyFrame.Value>
                                    </DiscreteObjectKeyFrame>
                                </ObjectAnimationUsingKeyFrames>

代碼非常簡(jiǎn)單,控制下內(nèi)圈的大小,還有是否隱藏而已。

這樣子我們就最終得到了頭圖的效果了

總的過程還是比較簡(jiǎn)單的。

完整代碼

下面是全部的代碼

<Window.Resources>
        <Geometry  x:Key="t1">
            M 20 40
                v 0 40
                h 0 7
                v 0 -40
                z
                M 30 42
                v 0  38
                h 40 0
                l 15 -35
                l -10 -5
                h -25 0 
                l 2 -20
            <!--小褶皺-->
            q -10 -10, -20 22
                z
        </Geometry>
        <Geometry  x:Key="t2">
            M 20 40
                v 0 40
                h 0 7
                v 0 -40
                z
                M 30 42
                v 0  38
                h 40 0
                l 15 -35
                l -10 -5
                h -25 0 
                l 2  0
            <!--小褶皺-->
            q -10 -10, -20 0
                z
        </Geometry>
        <PathGeometry  Figures="   M 20 40 l 2 -5 v 0 5 h -2 0  z" x:Key="roue"/>
    </Window.Resources>
    <Grid>
        <Border  BorderThickness="2" Background="Transparent" BorderBrush="BlueViolet"   CornerRadius="100" Width="200" Height="{Binding  RelativeSource={RelativeSource Mode=Self}, Path=Width}" Grid.Column="1" Grid.Row="1">
            <Border x:Name="sor" Visibility="Hidden" BorderThickness="2" Background="Transparent" BorderBrush="Salmon"   CornerRadius="100" Width="200" Height="{Binding  RelativeSource={RelativeSource Mode=Self}, Path=Width}" Grid.Column="1" Grid.Row="1"/>
        </Border>
        <Grid Width="300" Height="300"   ShowGridLines="False">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition />
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Path StrokeThickness="2"   Grid.Column="1" Grid.Row="1" VerticalAlignment="Bottom" Stretch="Uniform" Fill="Pink" Width="80" Height="80" Stroke="Blue" Data="{StaticResource t1}" RenderTransformOrigin="0.5,0.5">
                <Path.RenderTransform>
                    <RotateTransform x:Name="rote" Angle="0"/>
                </Path.RenderTransform>
                <Path.Triggers>
                    <EventTrigger  RoutedEvent="MouseLeftButtonDown">
                        <BeginStoryboard x:Name="Bs1">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetProperty="Data">
                                    <DiscreteObjectKeyFrame KeyTime="0:0:0.01">
                                        <DiscreteObjectKeyFrame.Value>
                                            <StaticResource ResourceKey="t2"/>
                                        </DiscreteObjectKeyFrame.Value>
                                    </DiscreteObjectKeyFrame>
                                </ObjectAnimationUsingKeyFrames>
                                <ThicknessAnimationUsingKeyFrames RepeatBehavior="Forever" Duration="0:0:0.4"  Storyboard.TargetProperty="Margin" >
                                    <SplineThicknessKeyFrame KeyTime="0:0:0.0" Value="4,3,0,0"/>
                                    <SplineThicknessKeyFrame KeyTime="0:0:0.2" Value="3,4,0,0"/>
                                    <SplineThicknessKeyFrame KeyTime="0:0:0.3" Value="0,0,4,0"/>
                                    <SplineThicknessKeyFrame KeyTime="0:0:0.35" Value="0,0,4,3"/>
                                    <SplineThicknessKeyFrame KeyTime="0:0:0.4" Value="4,3,0,0"/>
                                </ThicknessAnimationUsingKeyFrames>
                                <DoubleAnimation   Duration="0:0:0.1" To="30" Storyboard.TargetName="rote" Storyboard.TargetProperty="Angle">
                                    <DoubleAnimation.EasingFunction>
                                        <CubicEase/>
                                    </DoubleAnimation.EasingFunction>
                                </DoubleAnimation>
                                <DoubleAnimation RepeatBehavior="Forever" SpeedRatio="1.2" Duration="0:0:1.5" To="0" Storyboard.TargetName="sor" Storyboard.TargetProperty="Width">
                                    <DoubleAnimation.EasingFunction>
                                        <CubicEase/>
                                    </DoubleAnimation.EasingFunction>
                                </DoubleAnimation>
                                <ObjectAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetName="sor" Storyboard.TargetProperty="Visibility">
                                    <DiscreteObjectKeyFrame KeyTime="0:0:0.1">
                                        <DiscreteObjectKeyFrame.Value>
                                            <Visibility>
                                                Visible
                                            </Visibility>
                                        </DiscreteObjectKeyFrame.Value>
                                    </DiscreteObjectKeyFrame>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                    <EventTrigger RoutedEvent="MouseLeftButtonUp">
                        <BeginStoryboard x:Name="Bs2">
                            <Storyboard>
                                <DoubleAnimation  FillBehavior="Stop"  Duration="0:0:0.5" To="-30" Storyboard.TargetName="rote" Storyboard.TargetProperty="Angle">
                                    <DoubleAnimation.EasingFunction>
                                        <CubicEase EasingMode="EaseOut"/>
                                    </DoubleAnimation.EasingFunction>
                                </DoubleAnimation>
                            </Storyboard>
                        </BeginStoryboard>
                        <RemoveStoryboard BeginStoryboardName="Bs1"/>
                    </EventTrigger>
                </Path.Triggers>
            </Path>
        </Grid>

以上就是基于WPF繪制一個(gè)點(diǎn)贊大拇指動(dòng)畫的詳細(xì)內(nèi)容,更多關(guān)于WPF繪制點(diǎn)贊動(dòng)畫的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • C# 中的委托詳細(xì)解析與完整應(yīng)用小結(jié)

    C# 中的委托詳細(xì)解析與完整應(yīng)用小結(jié)

    C#委托是一種類型安全的函數(shù)指針,允許將方法作為參數(shù)傳遞或賦值給變量,它在事件處理、回調(diào)和異步編程中廣泛應(yīng)用,本文詳細(xì)介紹了委托的基本概念、用法和高級(jí)應(yīng)用,感興趣的朋友一起看看吧
    2025-03-03
  • C#中的Linq?to?JSON操作詳解

    C#中的Linq?to?JSON操作詳解

    本文詳細(xì)講解了C#中的Linq?to?JSON操作,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-06-06
  • [C#].NET中幾種Timer的使用實(shí)例

    [C#].NET中幾種Timer的使用實(shí)例

    本篇文章主要介紹了.NET中幾種Timer的使用,具有一定的參考價(jià)值,有興趣的可以了解一下。
    2016-12-12
  • c# 如何自己實(shí)現(xiàn)一個(gè)ORM框架

    c# 如何自己實(shí)現(xiàn)一個(gè)ORM框架

    這篇文章主要介紹了c# 如何自己實(shí)現(xiàn)一個(gè)ORM,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-03-03
  • C#用遞歸算法解決經(jīng)典背包問題

    C#用遞歸算法解決經(jīng)典背包問題

    背包問題有好多版本,本文只研究0/1版本,即對(duì)一個(gè)物體要么選用,要么就拋棄,不能將一個(gè)物體再繼續(xù)細(xì)分的情況。
    2016-06-06
  • C#實(shí)現(xiàn)文件斷點(diǎn)續(xù)傳下載的方法

    C#實(shí)現(xiàn)文件斷點(diǎn)續(xù)傳下載的方法

    這篇文章主要介紹了C#實(shí)現(xiàn)文件斷點(diǎn)續(xù)傳下載的方法,涉及網(wǎng)絡(luò)文件操作的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-05-05
  • C#中如何限制TextBox控件內(nèi)輸入值的范圍

    C#中如何限制TextBox控件內(nèi)輸入值的范圍

    這篇文章主要介紹了C#中如何限制TextBox控件內(nèi)輸入值的范圍,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • C#實(shí)現(xiàn)功能強(qiáng)大的中國(guó)農(nóng)歷日歷操作類

    C#實(shí)現(xiàn)功能強(qiáng)大的中國(guó)農(nóng)歷日歷操作類

    這篇文章主要介紹了C#實(shí)現(xiàn)功能強(qiáng)大的中國(guó)農(nóng)歷日歷操作類,實(shí)例分析了C#操作時(shí)間及字符串的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-03-03
  • C# LINQ的基本使用方法示例

    C# LINQ的基本使用方法示例

    這篇文章主要給大家介紹了關(guān)于C# LINQ的基本使用教程,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用C# LINQ具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • C# 圖片與二進(jìn)制轉(zhuǎn)換的簡(jiǎn)單實(shí)例

    C# 圖片與二進(jìn)制轉(zhuǎn)換的簡(jiǎn)單實(shí)例

    這篇文章介紹了C# 圖片與二進(jìn)制轉(zhuǎn)換的簡(jiǎn)單實(shí)例,有需要的朋友可以參考一下
    2013-09-09

最新評(píng)論

山西省| 玛沁县| 文化| 苗栗县| 平顺县| 米林县| 定兴县| 峨眉山市| 曲松县| 黑水县| 陇西县| 巧家县| 新巴尔虎左旗| 丰城市| 个旧市| 东乌| 合山市| 玉田县| 丰宁| 曲麻莱县| 沛县| 沅江市| 盈江县| 宜君县| 清远市| 丘北县| 郧西县| 南宫市| 绿春县| 依兰县| 故城县| 饶平县| 沁阳市| 湖州市| 平远县| 水富县| 三河市| 增城市| 高雄市| 吉首市| 庆阳市|