自定义UIViewController的转场动画
iOS7开始提供了一系列自定义ViewController转场的API
1.UIViewControllerAnimatedTransitioning协议 : 用来自定义一个非交互式的切换动画
```
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext;
//定义动画过程
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext;
```
2.UIViewControllerContextTransitioning 协议:转场动画的上下文
```
- (UIView *)containerView; //用来控制VC切换的容器,将需要push或present进来的view加入改view
//根据key返回对应的Controller key的值:UITransitionContextToViewControllerKey or UITransitionContextFromViewControllerKey
- (UIViewController *)viewControllerForKey:(NSString *)key;
- (void)completeTransition:(BOOL)didComplete;
```
3.UINavigationControllerDelegate :自定义pop和push动画
```
//返回自定义的pop或者push动画, 改动画实现了UIViewControllerAnimatedTransitioning
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC ;
```
4.UIViewCotrollerTransitioningDelegate : 自定义dismiss和present动画
```
-(id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source;
-(id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed;
```
- 自定义的动画需要实现UIViewControllerAnimatedTransitioning协议 ,再根据UIViewControllerContextTransitioning协议提供的方法做动画
- 在firstViewController里实现UIViewCotrollerTransitioningDelegate 或 UIViewCotrollerTransitioningDelegate,在对应的代理方法里返回第一步自定义的动画
self.navigationController.delegate = self;或者 secondVc.transitioningDelegate = self;