当前位置: 代码迷 >> Iphone >> 自定义转场卡通片的实现
  详细解决方案

自定义转场卡通片的实现

热度:153   发布时间:2016-04-25 05:28:45.0
自定义转场动画的实现

现在的APP有很多酷炫的动画,看了心痒痒地想加点动画到自己的APP上,增加一些交互效果.现在很常见的动画就是转场动画,先来介绍一下专场动画的实现.

1. 转场动画

其实iOS对转场动画的支持非常好,基本上只要实现几个协议就行了,把四个协议弄清楚了,基本上就可以在上面实现各种各样酷炫的转场动画了.

@protocol UIViewControllerContextTransitioning

故名思议,这个就是提供上下文.这个系统已经实现好了,可以直接得到fromViewController,toViewController,ContainerView等,直接看看源码就会用了.

@protocol UIViewControllerAnimatedTransitioning

这个是动画的核心,主要是实现

-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext

就是在这个方法里来写动画效果 

@protocol UIViewControllerTransitioningDelegate

@protocol UINavigationControllerDelegate

这两个协议的作用是一样的,用大白话来说就是问你要不要用转场动画,主要的方法就是返回一个实现了UIViewControllerAnimatedTransitioning协议的动画

 

-(id< UIViewControllerAnimatedTransitioning >)animationControllerForPresentedController:(UIViewController )presented presentingController:(UIViewController )presenting sourceController:(UIViewController *)source;
对应self presentViewController

 -(id< UIViewControllerAnimatedTransitioning >)animationControllerForDismissedController:(UIViewController *)dismissed;

对应self dismissViewController

-(id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC

对应self.navigationController pushViewController

 主要就是上面三个方法.

还有一个协议@protocol UIViewControllerInteractiveTransitioning

这个主要是和手势有关,就是交互效果,我这实现的demo没有用这个.

 

2. demo效果

 

3. demo

代码量很少,自己看看就可以实现自己的酷炫动画了.

github地址:https://github.com/stevenxiaoyang/NavTransition.git

欢迎大家一起交流进步

 

 

 

 

  相关解决方案