presentViewController并显示导航栏 [英] presentViewController and displaying navigation bar

查看:136
本文介绍了presentViewController并显示导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图控制器层次结构,最顶层的控制器显示为模态,想知道如何在使用时显示导航栏

I have a view controller hierarchy and the top-most controller is displayed as a modal and would like to know how to display the navigation bar when using

'UIViewController:presentViewController:viewControllerToPresent:animated:completion'

'presentViewController:animated:completion:'note:

The docs for 'presentViewController:animated:completion:' note:


'在iPhone和iPod touch上,呈现的视图始终为全屏。
在iPad上,演示文稿取决于
modalPresentationStyle属性中的值。'

'On iPhone and iPod touch, the presented view is always full screen. On iPad, the presentation depends on the value in the modalPresentationStyle property.'

对于'modalPresentationStyle' ,文档说:

For 'modalPresentationStyle', the docs say:


演示文稿样式决定了模式呈现的视图控制器在屏幕上的显示方式。在iPhone和iPod touch上,模态视图控制器始终以全屏显示,但在iPad上有几种不同的显示选项。

The presentation style determines how a modally presented view controller is displayed onscreen. On iPhone and iPod touch, modal view controllers are always presented full-screen, but on iPad there are several different presentation options.

一旦视图控件显示自己,有没有办法确保状态栏下方的导航栏可见?我应该将文档解释为,你没有获得iPhone / iPod的任何选项,只能在iPad上使用?

Is there way to ensure that the navigation bar is visible below the status bar once the view control displays itself? Should I interpret the doc as, you don't get any options of iPhone/iPod and only on iPad?

以前,我使用' UIViewController:presentModalViewController:动画'运行良好,但自iOS 5.0以来,API已被弃用,所以我转换到新的。

Previously, I was using 'UIViewController:presentModalViewController:animated' which worked fine, but since iOS 5.0, the API has been deprecated so I'm switching over to the new one.

从视觉上看,我要做的是从屏幕底部插入新的控制器,就像过去的旧API一样。

Visually, what I'm looking to do is have the new controller slide in from the bottom of the screen, just like the old API used to do.

[使用代码更新]:

// My root level view:
UIViewController *vc = [[RootViewController alloc] 
                            initWithNibName:nil 
                            bundle:[NSBundle mainBundle]];
navController = [[UINavigationController alloc] initWithRootViewController:vc];        
....

// Within the RootViewController, Second view controller is created and added 
// to the hierarchy. It is this view controller that is responsible for 
// displaying the DetailView:
SecondTierViewController *t2controller = [[SecondTierViewController alloc] 
                                           initWithNibName:nil
                                           bundle:[NSBundle mainBundle]];

[self.navigationController pushViewController:t2controller animated:YES];

// Created by SecondTierViewController 
DetailViewController *controller = [[DetailViewController alloc] initWithNibName:nil                                                                                 
                                        bundle:[NSBundle mainBundle]];  

controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
controller.modalPresentationStyle = UIModalPresentationCurrentContext;

[self.navigationController presentViewController:controller 
                                        animated:YES 
                                        completion:nil];


推荐答案

如果以模态方式呈现视图控制器,确实如此在iPhone上,无论您如何将其呈现在导航控制器的顶视图控制器上或任何其他方式,它都将全屏显示。但是你总是可以这样显示导航栏:

It is true that if you present a view controller modally on the iPhone, it will always be presented full screen no matter how you present it on the top view controller of a navigation controller or any other way around. But you can always show the navigation bar this way:

而不是呈现视图控制器模态地呈现导航控制器,其根视图控制器设置为你想要的视图控制器:

Rather than presenting that view controller modally present a navigation controller modally with its root view controller set as the view controller you want:

MyViewController *myViewController = [[MyViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navigationController = 
    [[UINavigationController alloc] initWithRootViewController:myViewController];

//now present this navigation controller modally 
[self presentViewController:navigationController
                   animated:YES
                   completion:^{

                        }];

当你的视图以模态呈现时,你会看到一个导航栏。

You should see a navigation bar when your view is presented modally.

这篇关于presentViewController并显示导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆