Iphone:可以隐藏TabBar吗? (iOS 8之前) [英] Iphone: Is it possible to hide the TabBar? (Pre-iOS 8)

查看:86
本文介绍了Iphone:可以隐藏TabBar吗? (iOS 8之前)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序使用 UITabBarController 来切换模式。在某种模式下,我想隐藏标签栏,直到该模式的步骤完成。请注意,我没有使用导航控制器,所以我无法使用导航控制器上的 setHidesBottomBarWhenPushed 方法隐藏标签栏。

I have an application that uses a UITabBarController to switch between modes. When in a certain mode, I'd like to hide the tab bar until the steps of that mode have been completed. Note that I'm not using a navigation controller so I can't use the setHidesBottomBarWhenPushed method on the navigation controller to hide the tab bar.

在iOS 8之前,当我尝试使用以下方法隐藏tarbar时:

Prior to iOS 8, When I attempt to hide the tarbar using:

self.tabBarController.tabBar.hidden = YES

标签栏消失,但底部留下50像素的空白区域标签栏曾经是的屏幕。我似乎无法弄清楚如何填补该区域。用户界面中该区域内的任何内容都会被裁剪,无法看到。

the tab bar goes away, but it leaves a 50 pixel blank area at the bottom of the screen where the tab bar used to be. I can't seem to figure out how to fill that area. Anything in the UI that is in that area is clipped and cannot be seen.

如果有可能,是否有任何想法?我真的很想远离导航控制器。

Any ideas if this is even possible? I'd really like to stay away from the navigation controller.

推荐答案

这是我的代码:

当然,这与控制器视图层次结构中的 goings on 相混淆。它可以改变/破坏。这使用定义的API,因此Apple不会关心,但他们也不会在意破坏您的代码。

This is, of course, mucking with the goings on in the controller's view hierarchy. It could change/break. This uses defined APIs, so Apple won't care, but they won't care about breaking your code, either.

- (void)hideTabBar {
  UITabBar *tabBar = self.tabBarController.tabBar;
  UIView *parent = tabBar.superview; // UILayoutContainerView
  UIView *content = [parent.subviews objectAtIndex:0];  // UITransitionView
  UIView *window = parent.superview;

  [UIView animateWithDuration:0.5
                   animations:^{
                     CGRect tabFrame = tabBar.frame;
                     tabFrame.origin.y = CGRectGetMaxY(window.bounds);
                     tabBar.frame = tabFrame;
                     content.frame = window.bounds;
                   }];

  // 1
}

- (void)showTabBar {
  UITabBar *tabBar = self.tabBarController.tabBar;
  UIView *parent = tabBar.superview; // UILayoutContainerView
  UIView *content = [parent.subviews objectAtIndex:0];  // UITransitionView
  UIView *window = parent.superview;

  [UIView animateWithDuration:0.5
                   animations:^{
                     CGRect tabFrame = tabBar.frame;
                     tabFrame.origin.y = CGRectGetMaxY(window.bounds) - CGRectGetHeight(tabBar.frame);
                     tabBar.frame = tabFrame;

                     CGRect contentFrame = content.frame;
                     contentFrame.size.height -= tabFrame.size.height;
                   }];

  // 2
}

编辑
匿名用户建议为7.0添加以下内容(我没有对此进行测试,也无法说明它是变通方法还是理想的实现方式):

Edit: An anonymous user has suggested the following addition for 7.0 (i have not tested this, and could not say whether it is a workaround or an ideal implementation):

// 1. To Hide the black line in IOS7 only, this extra bit is required
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    [self.tabBarController.tabBar setTranslucent:YES];
}  

// 2. For IOS 7 only
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    [self.tabBarController.tabBar setTranslucent:NO];
}

编辑:在8.x中完全未经测试可能缺少一些布局。

Edit: Entirely untested in 8.x and likely lacking in some layouts.

这篇关于Iphone:可以隐藏TabBar吗? (iOS 8之前)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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