- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {_transitionContext = transitionContext;//首先记录transitionContext,下面的方法会用到 //我们主要通过这个transitionContext来获取需要做动画的fromViewController和toViewController,fromView和toView //通过viewControllerForKey:这个方法来获取,有两个key来获取相应的Controller // Currently only two keys are defined by the system: // UITransitionContextToViewControllerKey 获取要出现的Controller // UITransitionContextFromViewControllerKey 获取要消失的Controller // Currently only two keys are defined by the system: // UITransitionContextToViewKey //获取要出现的view即上面toViewController的View // UITransitionContextFromViewKey //获取要出现的view即fromViewController的View UIView *fromView = [transitionContext viewForKey:UITransitionContextFromViewKey]; UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey]; //拿到ContainerView UIView *containerView = [transitionContext containerView]; //把fromView和toView都加到containerView中,在容器中是完成动画 [containerView addSubview:toView]; [containerView addSubview:fromView];
fromView.layer.transform = CATransform3DMakeRotation(-M_PI_2, 0, 1, 0); } completion:^(BOOL finished) { // This must be called whenever a transition completes (or is cancelled.) // Typically this is called by the object conforming to the // UIViewControllerAnimatedTransitioning protocol that was vended by the transitioning // delegate. For purely interactive transitions it should be called by the // interaction controller. This method effectively updates internal view // controller state at the end of the transition. //动画完成后必须调用 [_transitionContext finishInteractiveTransition]; [_transitionContext completeTransition:YES]; }]; }