ilmiacs
ilmiacs

Reputation: 2576

Translucent UINavigationController, presented modally

How can one present a UINavigationController such that the view it was presented from is still visible in the background?

My experience is that the UINavigationController will clip anything below its view, so setting UINavigationController.view.alpha will uncover a fixed color background, not the presenting view's content.

Can this be changed?

EDIT

I am not interested in the navigation bar, but the full content the navigation controller manages.

Upvotes: 0

Views: 704

Answers (3)

Alexis C.
Alexis C.

Reputation: 4918

There is now a way to achieve this using the iOS7 custom transitions, this way :

MyController * controller = [MyController new];
[controller setTransitioningDelegate:self.transitionController];
controller.modalPresentationStyle = UIModalPresentationCustom;
[self controller animated:YES completion:nil];

To create your custom transition, you need 2 things :

  • A TransitionDelegate object (implementing <UIViewControllerTransitionDelegate>)
  • An "AnimatedTransitioning" object (implementing <UIViewControllerAnimatedTransitioning>)

You can find more informations on custom transitions in this tutorial : http://www.doubleencore.com/2013/09/ios-7-custom-transitions/

Upvotes: 1

Kasper Welner
Kasper Welner

Reputation: 545

The problem is not the UINavigationController, but the fact that you present it modally. ViewControllers presented modally can never be transparent.

You can fake a modal presentation by adding you UINavigationControllers view as a subview to the main UIWindow.

This example works for me when testing in XCode:

   UIViewController *viewController = [[UIViewController alloc] init];
   viewController.view.backgroundColor = [[UIColor greenColor] colorWithAlphaComponent:0.35];

   UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:viewController];

   [[[[UIApplication sharedApplication] delegate] window] addSubview:navCon.view];

Of course you will have to do any animated transition yourself, but that should be trivial using animation blocks.

Upvotes: 4

tkanzakic
tkanzakic

Reputation: 5499

if you wish this behavior you can not use a UINavigationController, as you say the navigation controller clip the view of the content controller. To do what you want you should add a navigator bar to your view instead, and simulate the actions of the navigation controller. To create a back button similar to the controller read this article

Upvotes: 0

Related Questions