半透明的UINavigationController,以模态呈现

时间:2013-02-06 13:26:07

标签: iphone ios objective-c ipad uikit

如何呈现UINavigationController以使其呈现的视图在后台仍然可见?

我的经验是UINavigationController会剪切其视图下方的任何内容,因此设置UINavigationController.view.alpha会发现固定的彩色背景,而不是呈现视图的内容。

可以改变吗?

修改

我对导航栏不感兴趣,但对导航控制器管理的全部内容不感兴趣。

3 个答案:

答案 0 :(得分:4)

问题不在于UINavigationController,而在于您以模态方式呈现它。以模态方式呈现的ViewControllers永远不会透明。

您可以通过将UINavigationControllers视图作为子视图添加到主UIWindow来伪造模态演示文稿。

在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];

当然,你必须自己做任何动画过渡,但使用动画块应该是微不足道的。

答案 1 :(得分:1)

现在有一种方法可以使用iOS7自定义过渡来实现这一点:

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

要创建自定义转换,您需要两件事:

  • TransitionDelegate对象(实现 <UIViewControllerTransitionDelegate>
  • “AnimatedTransitioning”对象 (实施<UIViewControllerAnimatedTransitioning>

您可以在本教程中找到有关自定义转换的更多信息:http://www.doubleencore.com/2013/09/ios-7-custom-transitions/

答案 2 :(得分:0)

如果你希望这种行为你不能使用UINavigationController,就像你说导航控制器剪辑内容控制器的视图一样。要执行您想要的操作,您应该在视图中添加导航栏,并模拟导航控制器的操作。要创建类似于控制器的后退按钮,请阅读this article

相关问题