如何嵌套UITabBarController
我试图将 UITabBar 嵌套在另一个 UITabBar 中,如下所示:(
UITabBarController *tabController = [[UITabBarController alloc] init];
tabController.delegate = self;
UITabBarController *friendsTabController = [[UITabBarController alloc] init];
FindFriendsViewController *findFriendsController = [[FindFriendsViewController alloc] initWithNibName:@"FindFriendsViewController" bundle:nil];
findFriendsController.rootViewController = self;
UINavigationController *findFriendsNavController = [[UINavigationController alloc] initWithRootViewController:findFriendsController];
findFriendsNavController.tabBarItem.title = NSLocalizedString(@"Add", nil);
friendsTabController.viewControllers = [NSArray arrayWithObjects:friendStreamController, friendListController, findFriendsNavController, nil];
tabController.viewControllers = [NSArray arrayWithObjects:nearbyNavController, friendsTabController, meController, checkInController, logController, nil];
显然,为了简洁起见,省略了一些代码,例如其他选项卡)
当我这样做时,然后单击外部选项卡栏的“朋友”选项卡,内部选项卡栏出现在外部选项卡栏的正上方。我不想要这个。我希望内部选项卡栏在选择时取代外部选项卡栏(位于窗口底部)。
我尝试通过隐藏外部选项卡栏,将其设置为隐藏在 UITabBarController 委托方法中来实现此目的,并且我尝试设置内部选项卡栏的框架以手动将其放置在屏幕底部,如下所示:
friendsTabController.tabBar.frame = CGRectMake(0, 430, 320, 50);
当我隐藏外部选项卡栏时,内部选项卡栏仍显示距屏幕下边缘相同的距离,而外部选项卡栏则被空白矩形替换。
当我尝试设置内部选项卡栏的框架时,其唯一可见的部分是外部选项卡栏框架之外的任何部分。
我尝试用谷歌搜索这个但无济于事。这种导航肯定并不罕见吧?在尝试此操作之前,我假设 SDK 会支持它。
有什么想法吗?
蒂亚,
汤姆
I am trying to nest a UITabBar inside another one, like so:
UITabBarController *tabController = [[UITabBarController alloc] init];
tabController.delegate = self;
UITabBarController *friendsTabController = [[UITabBarController alloc] init];
FindFriendsViewController *findFriendsController = [[FindFriendsViewController alloc] initWithNibName:@"FindFriendsViewController" bundle:nil];
findFriendsController.rootViewController = self;
UINavigationController *findFriendsNavController = [[UINavigationController alloc] initWithRootViewController:findFriendsController];
findFriendsNavController.tabBarItem.title = NSLocalizedString(@"Add", nil);
friendsTabController.viewControllers = [NSArray arrayWithObjects:friendStreamController, friendListController, findFriendsNavController, nil];
tabController.viewControllers = [NSArray arrayWithObjects:nearbyNavController, friendsTabController, meController, checkInController, logController, nil];
(obviously, some of the code, such as the other tabs is ommitted for brevity)
When I do this, and click on the "Friends" tab of the outer tab bar, the inner tab bar appears directly above the outer one. I don't want this. I would like the inner tab bar to take the place (at the bottom of the window) of the outer one when it is selected.
I've tried doing this by hiding the outer tab bar, by setting it to hidden in the UITabBarController delegate method, and I've tried setting the frame of the inner tab bar to manually position it at the bottom of the screen like so:
friendsTabController.tabBar.frame = CGRectMake(0, 430, 320, 50);
When I hide the outer tab bar the inner one still appears the same distance from the bottom edge of the screen, and the outer one is replaced by a blank rectangle.
When I try setting the frame of the inner tab bar, the only part of it that is visible is any part that would be outside the frame of the outer tab bar.
I've tried googling this to no avail. Surely this kind of navigation is not so rare? Before attempting this I had assumed it would be supported in the SDK.
Any ideas?
TIA,
Tom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试在应用程序中使用单个选项卡栏控制器。当用户单击导致一组新选项卡的选项卡时,替换单选项卡栏控制器中的所有选项卡。我不确定您是否导航“返回”到顶层,但我想您心里有数。
我不认为这是一个很棒的用户界面,但你也许可以让它以这种方式工作。
You could try having a single tab-bar controller in your app. When a user clicks on a tab that leads to a new set of tabs, replace all of the tabs in the single-tab-bar controller. I'm not sure you navigate "back" to the top level, but I presume you have something in mind.
I dont think this is great UI, but you can probably make it work this way.
我认为解决您的问题的更好方法是在您想要嵌套第二个 tabBarController 的选项卡中的 viewController 中添加一个 containerView 。然后,您可以将 childViewController 添加到该 containerView 中,并以与 tabBarController 几乎相同的方式为这些 childViewController 创建自定义 Segue。这使您可以选择将新的自定义“选项卡栏”(我推荐使用分段控件)放置在包含容器视图的视图控制器中的任何位置。我认为这是处理嵌套 tabBarController 的更可接受的方式。用户也不会因 tabBar 突然改变外观而感到困惑。
I think a better solution to your problem would be to add a containerView to the viewController in the tab that you would like to nest the second tabBarController. Then you can add childViewControllers to that containerView and create a custom segue to those childViewControllers in much the same way a tabBarController does. This gives you the option to put your new custom "tab bar" ( I recommend a segmentedControl ) anywhere you like in the viewController containing the containerView. I think it's a more acceptable way to handle a nested tabBarController. Also the user will not be confused with a tabBar suddenly changing appearance.