在 TabBar 上方呈现 UIViewController [英] Present UIViewController above TabBar

查看:45
本文介绍了在 TabBar 上方呈现 UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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?

推荐答案

假设 ViewControllerATabBarControllerUIViewController.而你想要呈现的 UIViewControllerViewControllerB

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];

在演示时,请确保为 ViewControllerBmodalPresentationStyle 属性设置了 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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