【发布时间】:2018-05-06 16:19:00
【问题描述】:
我正在使用 TabBarController,我想从其中一个选项卡中呈现另一个 UIViewController,同时保持 TabBar 显示。
如果我只是展示或推动视图控制器,它会在 TabBar 上方全屏显示。
解决这个问题的正确方法是什么?
【问题讨论】:
标签: objective-c uitabbarcontroller tabbar presentviewcontroller
我正在使用 TabBarController,我想从其中一个选项卡中呈现另一个 UIViewController,同时保持 TabBar 显示。
如果我只是展示或推动视图控制器,它会在 TabBar 上方全屏显示。
解决这个问题的正确方法是什么?
【问题讨论】:
标签: objective-c uitabbarcontroller tabbar presentviewcontroller
假设ViewControllerA 是UIViewController 的TabBarController。而你要呈现的UIViewController是ViewControllerB
推送ViewControllerB,同时保持 TabBar 显示。只需在ViewControllerA 中调用即可
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];
在演示时,请确保将 UIModalPresentationOverCurrentContext 设置为 ViewControllerB 的 modalPresentationStyle 属性。如果没有,它将在TabBar 上显示全屏
为了便于理解,我创建了a demo repo,你可以看看。
【讨论】: