在子视图上隐藏选项卡栏控制器
我发现这个问题有很多变化,但只是想澄清一下,因为我似乎无法让我的工作发挥作用。
我有一个 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 UIViewController
s (Each Tab). On one of these UIViewController
s (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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
hidesBottomBarWhenPushed
仅当您将视图控制器推送到UINavigationController
堆栈时才相关。您使用addSubview:
所做的就是将game1
的视图添加到当前视图控制器的视图中。这是完全不对的,UIKit 根本不会处理这个问题。您应该将
UINavigationController
作为选项卡的视图控制器,然后使用类似以下内容的内容推送game1
视图控制器:而不是
addSubview:
。然后,这将与 hidesBottomBarWhenPushed 一起使用。但请注意,最好在game1
类的init
方法中设置hidesBottomBarWhenPushed
,而不是在viewDidLoad
中设置代码>.hidesBottomBarWhenPushed
is only relevant when you're pushing the view controller onto aUINavigationController
stack. What you're doing with theaddSubview:
is that you're just adding the view ofgame1
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 thegame1
view controller with something like:instead of
addSubview:
. That will then work withhidesBottomBarWhenPushed
. Note however that it's probably best to sethidesBottomBarWhenPushed
in the yourinit
method of whatever classgame1
is, rather than inviewDidLoad
.