lottie-ios学习笔记

888 阅读1分钟

地址:github.com/airbnb/lott… 很多简友说这个没有OC版本的了都是swift版本, 我暂时传了一个 OC以前版本到自己的Git仓库 pod 刚刚上传了 可以用下面的进行安装 如果搜索不到请更新pod 库

用自己保存的版本
   pod 'lottie-ios_Oc'
或者指定版本
pod 'lottie-ios', '~> 2.5.3'

oc版本 素材下载地址:www.lottiefiles.com/ 下载下来是 json 文件 oc 语言使用 pod 安装 pod 'lottie-ios' pod install 命令 完成后 导入头文件

#import <lottie-ios/Lottie/LOTAnimationView.h>
    LOTAnimationView *animation = [LOTAnimationView animationNamed:@"ripple"];
	animation.backgroundColor = [UIColor redColor];
	animation.frame = CGRectMake(0, 100, 300, 300);
	[self.view addSubview:animation];

//执行动画有两种方式 
#mark 第一种 全部执行完
[animation playWithCompletion:^(BOOL animationFinished) {
  // Do Something
}];
# mark 也可以直接设置动画进度
animation.animationProgress = progress;
# mark 还可以使用 
[animation playFromProgress:0.25 toProgress:0.5 withCompletion:^(BOOL animationFinished) {
  // Do Something
}];

# mark 从官方摘抄代码
// ===========  还可以自定义present 动画  ======= 

 ToAnimationViewController *vc = [[ToAnimationViewController alloc] init];
  vc.transitioningDelegate = self;
  [self presentViewController:vc animated:YES completion:NULL];
#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" applyAnimationTransform:NO];
  return animationController;
}
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
  LOTAnimationTransitionController *animationController = [[LOTAnimationTransitionController alloc] initWithAnimationNamed:@"vcTransition2" fromLayerNamed:@"outLayer" toLayerNamed:@"inLayer" applyAnimationTransform:NO];
  return animationController;
}