My ViewController hierachy is as follows:
UITabbarcontroller
->UINavigationController1
->FirstViewController
->UINavigationController2
->UIViewController
So I want to push a SecondViewController on top of my FirstViewController. The custom transition I need is for the SecondViewController to fade in and my FirstViewController to fade out.
Here is my code:
FirstViewController:
- (void)didTapButton:(id)sender
{
SecondViewController* vc = [[SecondViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
UINavigationController1Delegate:
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
MyAnimatedTransitioning *transitioning = [[MyAnimatedTransitioning alloc] init];
return transitioning;
}
MyAnimatedTransitioning:
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
[transitionContext.containerView addSubview:toViewController.view];
toViewController.view.alpha = 0;
fromViewController.view.alpha = 1.0;
[UIView animateKeyframesWithDuration:0.25 delay:0 options:0 animations:^{
fromViewController.view.alpha = 0;
toViewController.view.alpha = 1.0;
} completion:^(BOOL finished) {
fromViewController.view.alpha = 1.0;
[transitionContext completeTransition:finished];
}];
}
I use a push style instead of the present style so that the navigation bar can cross fade nicely. However the problem that I faced is that I still see my tabbar at the bottom(from the tabbarcontroller) being pushed to the left during the transition. What I need is for the tabbar to fade out nicely too. Anyone has any good ideas on how to do this?
I ended up using present style instead of the push style. Works well enough for me