gpt4 book ai didi

ios - presentViewController 和显示导航栏

转载 作者:IT王子 更新时间:2023-10-29 07:30:42 29 4
gpt4 key购买 nike

我有一个 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com