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进行渲染。