ios - presentViewController 和显示导航栏

标签 ios iphone uiviewcontroller modalviewcontroller presentmodalviewcontroller

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

'UIViewController:presentViewController:viewControllerToPresent:animated:completion'

“presentViewController:animated:completion:”的文档注意:

'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”,文档说:

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.

有没有办法确保在 View 控件显示自身后导航栏在状态栏下方可见?我是否应该将文档解释为,您没有任何 iPhone/iPod 选项并且只能在 iPad 上使用?

以前,我使用的是 'UIViewController:presentModalViewController:animated',它运行良好,但自 iOS 5.0 以来,该 API 已被弃用,因此我切换到新 API。

在视觉上,我想要做的是让新 Controller 从屏幕底部滑入,就像以前的旧 API 一样。

[用代码更新]:

// 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 上以模态方式呈现 View Controller ,无论您如何将它呈现在导航 Controller 的顶部 View Controller 或任何其他方式上,它总是会全屏呈现。但是您始终可以使用以下解决方法显示导航栏:

与其以模态方式呈现该 View Controller ,不如以模态方式呈现导航 Controller ,并将其 Root View Controller 设置为您想要的 View Controller :

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:^{

                        }];

当您的 View 以模态方式呈现时,您应该会看到一个导航栏。

关于ios - presentViewController 和显示导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9724194/

相关文章:

ios - 使用 Expo 构建二进制文件是否会压缩应用程序的大小?

iphone - 如何从 PhotoLibrary 获取图像作为附件

javascript - 开源钛开发者的源代码藏在哪里?

ios5 - instantiateViewControllerWithIdentifier 使应用程序崩溃

ios - UISplitViewController - 在主视图 Controller 中点击单元格会导致在主视图 Controller 中出现 segue,而不是在详细 View Controller 中

mysql - iOS 应用程序开发 - 数据库

ios - CCSprite 在边框周围有奇怪的白色像素

iphone - 更改地址簿中人员的联系人照片

ios - 在 Swift 中加载 UIView 时自定义转换出错

ios - UICollectionView:删除单元格之间的空间(每行 7 个项目)