【开源】LLMAnimator 60多种动画让你的应用动起来
github: https://github.com/brookshi/LLMAnimator ,欢迎star/fork
之前做android的时候需要给应用加些动画效果,在github上找到这个库:
https://github.com/daimajia/AndroidViewAnimations,用起来挺方便,效果也不错。
现在做uwp,想要加些动画就想到这个库,于是开发了LLMAnimator,算是上面android库的uwp移植版本。
先看效果:
用起来也很简单:
1 Animator.Use(AnimationType.Bounce) //使用哪种动画 2 .SetDelay(TimeSpan.FromSeconds(3)) //延迟执行,默认立即执行 3 .SetDuration(TimeSpan.FromMilliseconds(1000)) //动画播放时间,每个动画都有自己的默认时间,一般不需要设置 4 .SetRepeatBehavior(new RepeatBehavior(10)) //重复次数,默认1次 5 .PlayOn(target); //动画目标 6 7 Animator.Use(AnimationType.Bounce).PlayOn(target); // 一般这样就好了,简单
动画类型都在AnimationType里面,有63种,算是包括各种常用的了,免去了自己创建动画一个一个写storyboard的痛苦。

1 public enum AnimationType 2 { 3 Bounce, 4 Flash, 5 Pulse, 6 RubberBand, 7 Shake, 8 StandUp, 9 Swing, 10 Tada, 11 Wave, 12 Wobble, 13 14 BounceIn, 15 BounceInDown, 16 BounceInUp, 17 BounceInLeft, 18 BounceInRight, 19 20 FadeIn, 21 FadeInDown, 22 FadeInUp, 23 FadeInLeft, 24 FadeInRight, 25 26 FadeOut, 27 FadeOutDown, 28 FadeOutUp, 29 FadeOutLeft, 30 FadeOutRight, 31 32 FlipInX, 33 FlipInY, 34 35 FlipOutX, 36 FlipOutY, 37 38 RotateIn, 39 RotateInDownLeft, 40 RotateInDownRight, 41 RotateInUpLeft, 42 RotateInUpRight, 43 44 RotateOut, 45 RotateOutDownLeft, 46 RotateOutDownRight, 47 RotateOutUpLeft, 48 RotateOutUpRight, 49 50 SlideInDown, 51 SlideInUp, 52 SlideInLeft, 53 SlideInRight, 54 55 SlideOutDown, 56 SlideOutUp, 57 SlideOutLeft, 58 SlideOutRight, 59 60 ZoomIn, 61 ZoomInDown, 62 ZoomInUp, 63 ZoomInLeft, 64 ZoomInRight, 65 66 ZoomOut, 67 ZoomOutDown, 68 ZoomOutUp, 69 ZoomOutLeft, 70 ZoomOutRight, 71 72 Hinge, 73 RollIn, 74 RollOut, 75 DropOut, 76 Landing, 77 TakingOff, 78 }
如果有其他动画需求,也可以留言。
实现也很简单,以Bounce为例:
1 public class BounceAnimation : AnimationBase 2 { 3 public BounceAnimation() 4 { 5 Duration = TimeSpan.FromMilliseconds(800); 6 } 7 8 public override IAnimation PlayOn(UIElement target, Action continueWith) 9 { 10 var transform = Utils.PrepareTransform(target, typeof(CompositeTransform)); 11 12 var storyboard = PrepareStoryboard(continueWith); 13 14 AddAnimationToStoryboard(storyboard, transform, CreateAnimation(), "TranslateY"); 15 16 storyboard.Begin(); 17 18 return this; 19 } 20 21 Timeline CreateAnimation() 22 { 23 DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames(); 24 var firstTimeSpan = TimeSpan.FromMilliseconds(Duration.TotalMilliseconds / 8); 25 26 frames.KeyFrames.Add(new EasingDoubleKeyFrame() 27 { 28 EasingFunction = new SineEase() 29 { 30 EasingMode = EasingMode.EaseIn 31 }, 32 KeyTime = KeyTime.FromTimeSpan(firstTimeSpan), 33 Value = -8, 34 }); 35 frames.KeyFrames.Add(new EasingDoubleKeyFrame() 36 { 37 EasingFunction = new BounceEase() 38 { 39 Bounces = 2, 40 Bounciness = 1.3, 41 EasingMode = EasingMode.EaseOut 42 }, 43 KeyTime = KeyTime.FromTimeSpan(Duration), 44 Value = 0, 45 }); 46 47 return frames; 48 } 49 }
和大家平常创建动画的过程一样,这个库只是把常用的动画都集合在一起,这样用起来很方便,希望大家喜欢。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?