问题描述
我正在使用 TabBarController,并且从其中一个选项卡中,我想呈现另一个 UIViewController,同时保持 TabBar 的显示.
I am using a TabBarController, and from one of the tabs, I want to present another UIViewController, while keeping the TabBar displayed.
如果我只是呈现或推动视图控制器,它会全屏显示,位于 TabBar 上方.
If I simply present or push the view controller, it is displayed in full screen, above the TabBar.
解决这个问题的正确方法是什么?
What is the right way to solve this issue?
推荐答案
假设 ViewControllerA
是 TabBarController
的 UIViewController
.而你想要呈现的 UIViewController
是 ViewControllerB
Assume ViewControllerA
is a UIViewController
of TabBarController
. And the UIViewController
you want to present is ViewControllerB
推送 ViewControllerB
,同时保持 TabBar 显示.只需在 ViewControllerA
中调用
To push ViewControllerB
, while keeping the TabBar displayed. Simply inside ViewControllerA
you just need to call
ViewControllerB *vc = // Initialize ViewControllerB here
[self.navigationController pushViewController:vc animated:YES];
呈现ViewControllerB
ViewControllerB *vc = Initialize ViewControllerB here
vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:vc animated:YES completion:nil];
在演示时,请确保为 ViewControllerB
的 modalPresentationStyle
属性设置了 UIModalPresentationOverCurrentContext
.如果没有,它将在 TabBar
With presenting, make sure you set UIModalPresentationOverCurrentContext
for modalPresentationStyle
property of ViewControllerB
. If not, it will present fullscreen, over the TabBar
为了更容易理解,我创建了一个演示仓库,你可以看看.
For easier understanding, i created a demo repo, you can take a look.
这篇关于在 TabBar 上方呈现 UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!