Airbnb的开源项目Lottie简易实现动画
2017-02-04 16:43
447 查看
Airbnb的开源项目Lottie简易实现动画
Lottie是Airbnb最近推出的开源项目,设计师只要使用AE把动画做出来,再使用Bodymovin插件就能把动画文件导出成json文件。这个json文件中包括动画的点的坐标,运行的轨迹等数据,在项目中引用这个开源库,使用这个json文件(或者URL)就可以实现动画,极快的完成了一个动画效果,要知道,简单的一个动画,用代码实现起来都需要花一定的时间。跨平台使用
这个库是跨平台的,只要设计出一套json动画描述文件,就可以支持Android,iOS,ReactNative,iOS目前是支持iOS8及以上的,同时支持OC和Swift,下面讲iOS的用法。支持使用Cocoapods和Carthage导入
pod 'lottie-ios' pod install
github "airbnb/lottie-ios" "master" carthage update
简单代码实现
加载json本地文件//加载本地的json描述文件 LAAnimationView *animation = [LAAnimationView animationNamed:@"Lottie"]; [self.view addSubview:animation]; //循环播放 animation.loopAnimation = YES; //1.直接开启 [animation playWithCompletion:^(BOOL animationFinished) { // Do Something }]; //2.手动开启 //设置动画的进度 //animation.animationProgress = 0 //[animation play] //手动关闭 //[animation pause]
加载URL
LAAnimationView *animation = [[LAAnimationView alloc] initWithContentsOfURL:[NSURL URLWithString:URL]]; [self.view addSubview:animation];
增加转场动画
#pragma mark -- View Controller Transitioning \\ - (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source { LAAnimationTransitionController *animationController = [[LAAnimationTransitionController alloc] initWithAnimationNamed:@"vcTransition1" fromLayerNamed:@"outLayer" toLayerNamed:@"inLayer"]; return animationController; } \\ - (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed { LAAnimationTransitionController *animationController = [[LAAnimationTransitionController alloc] initWithAnimationNamed:@"vcTransition2" fromLayerNamed:@"outLayer" toLayerNamed:@"inLayer"]; return animationController; }
Swift实现
let animationView = LAAnimationView.animationNamed("hamburger") self.view.addSubview(animationView!) animationView?.play(completion: { (finished) in // Do Something })
相关文章
这个项目碉堡了Airbnb/Lottie-iOS
相关文章推荐
- 用开源项目ActivityOptionsICS让ActivityOptions的动画实现兼容
- [置顶] RxJava+Retrofit+okhttp+mvp+butterknife实现的简易开源项目
- 用开源项目ActivityOptionsICS让ActivityOptions的动画实现兼容
- 用开源项目JazzyViewPager实现ViewPager切换动画
- airbnb开源动画库lottie
- 用开源项目JazzyViewPager实现ViewPager切换动画
- AE 动画直接变原生代码:Airbnb 发布开源动画库 Lottie
- Github最火开源项目-三十秒实现QQ首页动画特效
- 用开源项目ActivityOptionsICS让ActivityOptions的动画实现兼容
- 开源项目推荐(3):Android UI Patterns 实现各种UI效果,含动画
- 用开源项目ActivityOptionsICS让ActivityOptions的动画实现兼容
- AE 动画直接变原生代码:Airbnb 发布开源动画库 Lottie
- 高分求救,微软屏传开源的项目,里面也有屏传的代码,是用C#实现的。
- 移植havlenapetr开源项目(利用FFMPEG实现播放器)
- 集成开源系统实现自动化构建、代码质量评估、项目信息统计
- IM 开源项目 群组服务 缓存设计实现之 成员属性
- IM 开源项目 群组服务 缓存设计实现之 群组属性
- 开源电子狗项目更新1.1 已实现PS3免引导盘游戏
- 关于Java RDP协议实现远程桌面连接的开源项目properjavardp
- 开源项目Html Agility Pack实现快速解析Html