UITabBarController 和旋转
我对 UITabBarController 有一个真正的问题。 我追求的结果如下: 1)在纵向模式下,一个简单的基于选项卡栏的应用程序(带有导航栏)没什么特别的。 2)在横向模式下,我想使用我自己的 UIViewController 完全忽略 UITabBar 。
我最后尝试的方法(我尝试了很多变体)我无法理解为什么不“工作”如下:
[TBC.view removeFromSuperView]; [AA.view addSubview:LSC.view];
当返回纵向时将其反转。
[LSC.view removeFromSuperView]; [AA.view addSubview:TBC.view];
我遇到的问题数量(嗯,它简单地旋转错误,创建了一个真正混乱的界面)是完全无法解释的。 看起来 tabbarcontroller 视图根本不“喜欢”处于标准视图层次结构中,而是希望直接附加到屏幕。 我想知道实现我的目标的最佳方法是什么,以及为什么选项卡栏不喜欢成为视图的子视图,
任何提示都非常受欢迎。
-t
I'm having a real issue with UITabBarController.
The outcome I'm after is the following:
1) in portrait mode, a simple tab bar based application (with navigation bars) nothing too fancy.
2) in landscape mode, I want to use my own UIViewController ignoring the UITabBar completely.
The approach (I tried many variants) I tried last which I fail to understand why is not "working" is the following:
going from portrait to landscape:
[TBC.view removeFromSuperView]; [AA.view addSubview:LSC.view];
and when returning to portrait reverse it.
[LSC.view removeFromSuperView]; [AA.view addSubview:TBC.view];
The amount of problems I have (well, it simple rotates wrongly creating a real messed up interface) are something completely unexplained. It seems like the tabbarcontroller view does not "like" at all to be in the standard view heirarchy but rather it wants to be attached directly to the screen.
I wonder what is the best approach to achieve my goal and why the tabbar does not like to be a subview of a view,
any hints mostly appreciated.
-t
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以防万一您仍然需要答案,或者其他人偶然发现了这个问题,我已经做了同样的事情并使其正常工作,但是您必须克服一些困难。 为了旋转 UITabBarController 的视图,您必须执行四件事:
我有一个 RootRotationController 可以执行此操作,如下所示:
此外,您应该知道 shouldAutorotateToInterfaceOrientation 在将根控制器的视图添加到窗口后立即被调用,因此您必须在完成后重新启用状态栏在您的应用程序委托中完成此操作。
Just in case you still need the answer, or someone else stumbles onto this, I've done the same thing and got it working, but there are a couple of hoops you have to jump through. In order to rotate a UITabBarController's view, there are four things you have to do:
I've got a RootRotationController that does this that looks like this:
In addition, you should know that shouldAutorotateToInterfaceOrientation is called just after adding the root controller's view to the window, so you'll have to re-enable the status bar just after having done so in your application delegate.
我认为你的问题来自于打字错误。 将removeFromSuperView 更改为removeFromSuperview。
尽管如此,它仍然有一个问题。 标签栏无法正确旋转。 它向上移动,直到消失。
不删除标签栏并使其透明怎么样?
Your problem comes from the typo, I think. Change removeFromSuperView to removeFromSuperview.
Though, it still has a problem. Tab bar doesn't rotate properly. It go upwards till it disappers.
How about not removing the tab bar, and make it transparent.
查看文档中的
UIViewController
实例方法rotatingFooterView
。或者,您可以自己管理 TabBar,而不是通过
UITabBarController
。Check out the
UIViewController
instance methodrotatingFooterView
in the docs.Or, you may manage TabBar by yourself, not through the
UITabBarController
.