0
votes

I have this storyboard :

TabBarController : Tab1 > NavigationController > VC1 > VC2 > VC3

// VC1.m
[self performSegueWithIdentifier:@"VC2" sender:self];

// VC2.m
[self performSegueWithIdentifier:@"VC3" sender:self];

I would like the transition between VC1 and VC2 to be a fade animation, but the transition between VC2 and VC3 the default one.

But I have to do a push segue and not modal to keep the benefits of UINavigationController (unless I'm missing something). All the solution I find for this are using presentViewController.

2

2 Answers

1
votes

Try using this CATransition

 CATransition *transition = [CATransition animation];
 transition.duration = 0.3;
 transition.type = kCATransitionFade;

 [navigationController.view.layer addAnimation:transition forKey:kCATransition];
 isPush ? [navigationController pushViewController:viewController animated:NO] : [navigationController popViewControllerAnimated:NO];
0
votes

If you insist on a segue than I see 2 ways:

1) Use UIViewControllerAnimatedTransitioning protocol and customize the transitions the way U like.

2) Write a custom UIStoryboardSegue

Or perform you own transitions and animations by means of manipulation of controllers and their views and frames smth like:

- (void)transitionToChildViewController:(UIViewController *)toViewController {

UIViewController *fromViewController = ([self.childViewControllers count] > 0 ? self.childViewControllers[0] : nil);
if (toViewController == fromViewController || ![self isViewLoaded]) {
    return;
}

UIView *toView = toViewController.view;
[toView setTranslatesAutoresizingMaskIntoConstraints:YES];
toView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
toView.frame = self.privateContainerView.bounds;

[fromViewController willMoveToParentViewController:nil];
[self addChildViewController:toViewController];
[self.privateContainerView addSubview:toView];
[fromViewController.view removeFromSuperview];
[fromViewController removeFromParentViewController];
[toViewController didMoveToParentViewController:self];

}

the last method perhaps is the most tedious.