• WPF和Expression Blend开发实例:Loading动画


    今天来点实际的,项目中可以真实使用的,一个Loading的动画,最后封装成一个控件,可以直接使用在项目中,先上图:

    整个设计比较简单,就是在界面上画18个Path,然后通过动画改变OpacityMask的值来实现一种动态的效果.

    因为整个过程比较简单,所以其实没有用到Blend,唯一一个需要注意的是Path的路径值是请美工从PS里生成的,路径如下:

    <Geometry x:Key="Block">
                M291.15499,85.897525 
                C291.15499,85.897525 
                 301.88917,85.87921 
                 301.88917,85.87921 
                 301.88917,85.87921 
                 300.38339,94.355061 
                 300.38339,94.355061 
                 300.38339,94.355061 
                 292.85366,94.355042 
                 292.85366,94.355042 
                 292.85366,94.355042 
                 291.15499,85.897525 
                 291.15499,85.897525Z
    </Geometry>

    Path的代码如下,每个Path一次旋转特定的角度围成一个圆形

    <Path x:Name="block0" Style="{StaticResource PathStyle}" Data="{StaticResource Block}"  OpacityMask="#00000000" >
         <Path.RenderTransform>
               <RotateTransform Angle="180"/>
          </Path.RenderTransform>
    </Path>
    <Style x:Key="PathStyle" TargetType="Path">
                <Setter Property="Fill" Value="#FF0092FF"></Setter>
                <Setter Property="Stretch" Value="Fill"></Setter>
                <Setter Property="RenderTransformOrigin" Value="0.5,5"></Setter>
                <Setter Property="VerticalAlignment" Value="Top"></Setter>
                <Setter Property="Height" Value="30"></Setter>
    </Style>

    单个Path的动画:

    <ColorAnimationUsingKeyFrames Duration="00:00:03.6" Storyboard.TargetName="block0" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                    <LinearColorKeyFrame KeyTime="00:00:00.0" Value="#FF000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:00.2" Value="#EF000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:00.4" Value="#E2000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:00.6" Value="#D3000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:00.8" Value="#C6000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:01.0" Value="#B7000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:01.2" Value="#AA000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:01.4" Value="#9B000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:01.6" Value="#8E000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:01.8" Value="#7F000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:02.0" Value="#72000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:02.2" Value="#63000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:02.4" Value="#56000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:02.6" Value="#3D000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:02.8" Value="#26000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:03.0" Value="#19000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:03.2" Value="#0C000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:03.4" Value="#00000000"/>
                    <LinearColorKeyFrame KeyTime="00:00:03.6" Value="#FF000000"/>
                </ColorAnimationUsingKeyFrames>

    源代码下载:

    https://files.cnblogs.com/youngytj/LoadingAnimations.rar

  • 相关阅读:
    【ROM修改教程】添加高级电源重启菜单(安卓4.0.4官方ROM)
    MTK 快速开机 技术详解
    MT6592 经验积累
    Android系统之Broadcom GPS 移植
    Android关机流程源码分析
    Android 4.1.2系统添加重启功能
    android4.2添加重启菜单项
    MTK平台 Android4.0.3 定制关机动画
    不进化,则消亡——互联网时代企业管理的十项实践
    前端切图:调用百度地图API
  • 原文地址:https://www.cnblogs.com/youngytj/p/4129365.html
Copyright © 2020-2023  润新知