动效在软件开发中非常常见,炫酷的动画能提升应用的B格,然而由设计师的设计转化成程序猿GG的代码是个非常“痛苦”的过程。对于复杂动画,可能要花费很多时间去研究和实现。Lottie 的出现,解决了这个尴尬的局面。它让复杂炫酷动效的实现变得容易很多。

  Lottie 是 Airbnb 在 github 上的开源项目,支持 iOS、Android、Rect Native多平台。通过 Adobe After Effect 插件 bodymovin 导出 JSON 文件,然后通过 lottie 加载 json 文件来实现动效,这样使得动画开发简单易行。

  项目传送门:

  Lottie-iOS: Lottie for iOS 下载。

  Lottie-Android:Lottie for Android 下载。

  Lottie-RectNative:Lottie for RectNative 下载。  

  Github 介绍:

  Lottie is a mobile library for Android and iOS that parses Adobe After Effects animations exported as json with bodymovin and renders the vector animations natively on mobile and through React Native!

  Lottie 是一个可应用于Andriod和iOS的动画库,它通过bodymovin插件来解析Adobe After Effects动画并导出为json文件,通过手机端原生的方式或者通过React Native的方式渲染出矢量动画。

  注:支持 iOS8+。

  官方实现效果图如下:

   

 

 

    

  

  AE 工具安装 及 插件配置 及 生成 JSON 文件参见 :本人的 Adobe After Effect For Mac 博文。

  

  东西准备好之后就可以开始实现动画了。

  使用:

  Lottie supports iOS 8 and above. Lottie animations can be loaded from bundled JSON or from a URL

  To bundle JSON just add it and any images that the animation requires to your target in xcode.

  可以通过加载本地 JSON 文件或一个 JSON 的URL 地址。

  示例代码: 

  1、通过本地 JSON 文件加载:

 LOTAnimationView *animation = [LOTAnimationView animationNamed:@"Lottie"];
[self.view addSubview:animation];
[animation playWithCompletion:^(BOOL animationFinished) {
// Do Something
}];

  2、通过 URL 加载:

 LOTAnimationView *animation = [[LOTAnimationView alloc] initWithContentsOfURL:[NSURL URLWithString:URL]];
[self.view addSubview:animation];

  可以直接设置动效的进度:

 CGPoint translation = [gesture getTranslationInView:self.view];
CGFloat progress = translation.y / self.view.bounds.size.height;
animationView.animationProgress = progress;

  可以支持自定义转场 controller:  

#pragma mark -- View Controller Transitioning

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source {
LOTAnimationTransitionController *animationController = [[LOTAnimationTransitionController alloc] initWithAnimationNamed:@"vcTransition1"
fromLayerNamed:@"outLayer"
toLayerNamed:@"inLayer"];
return animationController;
} - (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
LOTAnimationTransitionController *animationController = [[LOTAnimationTransitionController alloc] initWithAnimationNamed:@"vcTransition2"
fromLayerNamed:@"outLayer"
toLayerNamed:@"inLayer"];
return animationController;
}

  Swift 支持:  

 let animationView = LOTAnimationView(name: "hamburger")
self.view.addSubview(animationView) animationView.play(completion: { finished in
// Do Something
})

  注:

  Animation file name should be first added to your project. as for the above code sample, It won't work until you add an animation file called hamburger.json.. let animationView = LOTAnimatedView.animationNamed("here_goes_your_json_file_name_without_.json")

  上面那些示例代码,动效文件应该先添加到工程中,才会执行动效。  

  AE 支持的特性

  Keyframe Interpolation


  • Linear Interpolation
  • Bezier Interpolation
  • Hold Interpolation
  • Rove Across Time
  • Spatial Bezier

  Solids


  • Transform Anchor Point
  • Transform Position
  • Transform Scale
  • Transform Rotation
  • Transform Opacity

  Masks


  • Path
  • Opacity
  • Multiple Masks (additive)

  Track Mattes


  • Alpha Matte

  Parenting


  • Multiple Parenting
  • Nulls

  Shape Layers


  • Anchor Point
  • Position
  • Scale
  • Rotation
  • Opacity
  • Path
  • Group Transforms (Anchor point, position, scale etc)
  • Rectangle (All properties)
  • Elipse (All properties)
  • Multiple paths in one group

  Stroke (shape layer)


  • Stroke Color
  • Stroke Opacity
  • Stroke Width
  • Line Cap
  • Dashes

  Fill (shape layer)


  • Fill Color
  • Fill Opacity

  Trim Paths (shape layer)


  • Trim Paths Start
  • Trim Paths End
  • Trim Paths Offset

  Layer Features


  • Precomps
  • Image Layers
  • Shape Layers
  • Null Layers
  • Solid Layers
  • Parenting Layers
  • Alpha Matte Layers

  当前不支持的AE特性

  • Even-Odd winding paths
  • Merge Shapes
  • Trim Shapes Individually feature of Trim Paths
  • Expressions
  • 3d Layer support
  • Gradients
  • Polystar shapes (Can convert to vector path as a workaround)
  • Alpha inverted mask

    

  

iOS开发之 Lottie -- 炫酷的动效的更多相关文章

  1. 李洪强IOS开发之iOS好项目收集

    李洪强IOS开发之iOS好项目收集 在这里收集一些最近出现的比较实用好玩的框架或者项目,会不断更新 项目 简述 日期 SCTableViewCell 类似与QQ侧滑删除Cell的Demo 201501 ...

  2. 李洪强iOS开发之iOS好文章收集

    李洪强iOS开发之iOS好文章收集 该文收集朋友们转发或自己的写的技术文章,如果你也有相关的好文章,欢迎留言,当好文章多的时候,我会对这些好文章进行分门别类 文章 简述 日期 直播服务配置 使用 ng ...

  3. 李洪强iOS开发之RunLoop的原理和核心机制

    李洪强iOS开发之RunLoop的原理和核心机制 搞iOS之后一直没有深入研究过RunLoop,非常的惭愧.刚好前一阵子负责性能优化项目,需要利用RunLoop做性能优化和性能检测,趁着这个机会深入研 ...

  4. iOS开发之Socket通信实战--Request请求数据包编码模块

    实际上在iOS很多应用开发中,大部分用的网络通信都是http/https协议,除非有特殊的需求会用到Socket网络协议进行网络数 据传输,这时候在iOS客户端就需要很好的第三方CocoaAsyncS ...

  5. iOS开发之UISearchBar初探

    iOS开发之UISearchBar初探 UISearchBar也是iOS开发常用控件之一,点进去看看里面的属性barStyle.text.placeholder等等.但是这些属性显然不足矣满足我们的开 ...

  6. iOS开发之UIImage等比缩放

    iOS开发之UIImage等比缩放 评论功能真不错 评论开通后,果然有很多人吐槽.谢谢大家的支持和关爱,如果有做的不到的地方,还请海涵.毕竟我一个人的力量是有限的,我会尽自己最大的努力大家准备一些干货 ...

  7. iOS开发之 Xcode6 添加xib文件,去掉storyboard的hello world应用

    iOS开发之  Xcode6.1创建仅xib文件,无storyboard的hello world应用 由于Xcode6之后,默认创建storyboard而非xib文件,而作为初学,了解xib的加载原理 ...

  8. iOS开发之loadView、viewDidLoad及viewDidUnload的关系

    iOS开发之loadView.viewDidLoad及viewDidUnload的关系 iOS开发之loadView.viewDidLoad及viewDidUnload的关系    标题中所说的3个方 ...

  9. iOS开发之info.pist文件和.pch文件

    iOS开发之info.pist文件和.pch文件 如果你是iOS开发初学者,不用过多的关注项目中各个文件的作用.因为iOS开发的学习路线起点不在这里,这些文件只会给你学习带来困扰. 打开一个项目,我们 ...

随机推荐

  1. JS关于全局变量跟局部变量的总结

    一.Javascript的变量的scope是根据方法块来划分的(也就是说以function的一对大括号{ }来划分).切记,是function块,而for.while.if块并不是作用域的划分标准,可 ...

  2. Robotframe work之环境搭建(一)

    准备安装如下:Python2.7.10.robot framework3.0.2.wxPython 2.8.12.1.robot framework-ride 1. 官网下载安装python,目前wx ...

  3. 第二章 Oracle数据库应用

    第二章   Oracle数据库应用2.1 表空间和用户权限下管理    2.1.1 表空间        2.1.1.1 分类:            永久性表空间            临时性表空间 ...

  4. 用 Python 和 Stanford CoreNLP 进行中文自然语言处理

    实验环境:Windows 7 / Python 3.6.1 / CoreNLP 3.7.0 一.下载 CoreNLP 在 Stanford NLP 官网 下载最新的模型文件: CoreNLP 完整包 ...

  5. zabbix主动上报的python脚本

    本代码linux.window平台通用. 不过我遇到一个Windows2008缺少运行库的提示,可能这个是Python3.6开发的.需要安装vc2015运行库吧.我没调试成功. linux平台还可以监 ...

  6. 二、AspNet Core添加EF的基本方法(简略版):

    _/\__ ---==/ \\ |. \|\ | ) \\\ \_/ | //|\\ / \\\/\\ 1.在Project.json的dependencies选项中添加以下引用: "Mic ...

  7. 用vuejs仿网易云音乐(实现听歌以及搜索功能)

    前言 前端时间学了vue,一开始看了vue1.0,后来实在觉得技术总得实践,就直接上手vue2.0.然后花了将近一周时间做了一个网易云音乐的小项目.一开始觉得项目比较小,没必要用vuex所以就没有使用 ...

  8. Unity 多屏(分屏)显示,Muti_Display

    Unity 多屏(分屏)显示,Muti_Display  最近项目有个需求,主要用于在展厅的展示游戏. 比如,在一个很大的展厅,很大的显示屏挂在墙上,我们不可能通过操作墙上那块显示器上的按钮来控制游戏 ...

  9. String转int数字格式异常问题

     写在前面的话 差不多一年前就计划写博客,可因为种种原因一直没有写,反而我身边的一些同学在我建议他们写博客不久之后就写了,比如张博同学,基本每次总结一个知识点就写一篇,这样不但方便自己以后查看翻阅,也 ...

  10. JavaScript异步编程

    前言 如果你有志于成为一个优秀的前端工程师,或是想要深入学习JavaScript,异步编程是必不可少的一个知识点,这也是区分初级,中级或高级前端的依据之一.如果你对异步编程没有太清晰的概念,那么我建议 ...