在子视图上隐藏选项卡栏控制器

发布于 2024-12-21 10:14:12 字数 716 浏览 4 评论 0原文

我发现这个问题有很多变化,但只是想澄清一下,因为我似乎无法让我的工作发挥作用。

我有一个 TabBarController (TBC),其中包含多个 UIViewController(每个选项卡)。在其中一个 UIViewController (mainMenu) 上,我尝试添加另一个 UIViewController (game1) 作为子视图:

[self.view addSubview:game1.view];

现在的问题是,它需要 TBC它,所以我尝试使用以下方法隐藏它:

self.hidesBottomBarWhenPushed = YES; //< (In the game1.m ViewDidLoad method)

game1.hidesBottomBarWhenPushed = YES; //< (In the mainMenu.m after I initialise game1)

猜测这是因为当我使用 addSubview 方法时菜单从未被推送?

最初我使用的是 presentModalViewController 方法,但框架被传递到新视图上,从而导致 UI 布局偏移/放大。

任何人都可以帮我解决这个问题,我似乎无法隐藏 TBC,我已经没有主意了。

提前致谢,埃利奥特

I have found lot's of variations for this question but just wanted some clarity on it as I can't seem to get mine working.

I have a TabBarController (TBC) which contains several UIViewControllers (Each Tab). On one of these UIViewControllers (mainMenu), I am trying to add another UIViewController (game1) as a subview:

[self.view addSubview:game1.view];

Now the issue with this is that it takes the TBC with it, so I tried hiding it using:

self.hidesBottomBarWhenPushed = YES; //< (In the game1.m ViewDidLoad method)

and

game1.hidesBottomBarWhenPushed = YES; //< (In the mainMenu.m after I initialise game1)

I am guessing that this is due to the menu never being pushed as I am using the addSubview approach?

Originally I was using the presentModalViewController approach but the frame is being passed onto the new view, thus causing the UI layout to be offset / zoomed in.

Can anyone help me fix this issue, I can't seem to hide the TBC and am running out of ideas.

Thanks in advanced, Elliott

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仙女 2024-12-28 10:14:12

hidesBottomBarWhenPushed 仅当您将视图控制器推送到 UINavigationController 堆栈时才相关。您使用 addSubview: 所做的就是将 game1 的视图添加到当前视图控制器的视图中。这是完全不对的,UIKit 根本不会处理这个问题。

您应该将 UINavigationController 作为选项卡的视图控制器,然后使用类似以下内容的内容推送 game1 视图控制器:

[self.navigationController pushViewController:game1 animated:YES];

而不是 addSubview:。然后,这将与 hidesBottomBarWhenPushed 一起使用。但请注意,最好在 game1 类的 init 方法中设置 hidesBottomBarWhenPushed,而不是在 viewDidLoad 中设置代码>.

hidesBottomBarWhenPushed is only relevant when you're pushing the view controller onto a UINavigationController stack. What you're doing with the addSubview: is that you're just adding the view of game1 into the current view controller's view. That is not right at all and UIKit won't handle that at all.

You should put a UINavigationController as the view controller for your tab, then push the game1 view controller with something like:

[self.navigationController pushViewController:game1 animated:YES];

instead of addSubview:. That will then work with hidesBottomBarWhenPushed. Note however that it's probably best to set hidesBottomBarWhenPushed in the your init method of whatever class game1 is, rather than in viewDidLoad.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文