Wrappres' Studio.

Lottie

字数统计: 173阅读时长: 1 min
2020/02/16 Share

Lottie

基本使用

1
2
3
4
5
LOTAnimationView *animation = [LOTAnimationView animationNamed:@"Lottie"];
[self.view addSubview:animation];
[animation playWithCompletion:^(BOOL animationFinished) {
// 动画完成后需要处理的事情
}];

动画与手势同步

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

自定义转场

1
2
3
4
5
6
7
8
9
10
11
12
13
#pragma mark -- 定制转场动画

// 代理返回推出控制器的动画
- (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;
}

实现原理

通过JSON文件映射到iOS的LayerModel,KeyFrame,ShapeItem,DashElement,Marker,Mask,Transform,再通过CoreAnimation进行渲染。

CATALOG
  1. 1. Lottie
    1. 1.1. 基本使用
    2. 1.2. 动画与手势同步
    3. 1.3. 自定义转场
    4. 1.4. 实现原理