简体   繁体   中英

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.

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.

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/

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM