iOS7无法隐藏tabbar,黑条

时间:2013-11-20 09:36:54

标签: ios objective-c ios7 hidden tabbar

我想在滚动集合视图时隐藏我的标签栏,代码是

 #pragma mark - UIScrollViewDelegate
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
    [self makeTabBarHidden:YES];
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self makeTabBarHidden:NO];
}

- (void)makeTabBarHidden:(BOOL)hide
{
    if ( [self.tabBarController.view.subviews count] < 2 )
    {
        return;
    }
    UIView *contentView;
    UIView *bradeView = [self.tabBarController.view.subviews objectAtIndex:2];

    if ( [[self.tabBarController.view.subviews objectAtIndex:0] 
             isKindOfClass:[UITabBar class]] )
    {
        contentView = [self.tabBarController.view.subviews objectAtIndex:1];
    }
    else
    {
        contentView = [self.tabBarController.view.subviews objectAtIndex:0];
    }
    //    [UIView beginAnimations:@"TabbarHide" context:nil];
    if ( hide )
    {
        contentView.frame = self.tabBarController.view.bounds;
    }
    else
    {
        contentView.frame = CGRectMake(self.tabBarController.view.bounds.origin.x,
                                 self.tabBarController.view.bounds.origin.y,
                                 self.tabBarController.view.bounds.size.width,
                                 self.tabBarController.view.bounds.size.height -
                                    self.tabBarController.tabBar.frame.size.height);
    }

    self.tabBarController.tabBar.hidden = hide;
    bradeView.hidden = hide;
}

但在iOS7中,当隐藏标签栏时,会出现一个不会消失的黑条。如何隐藏iOS7中的tabbar?

4 个答案:

答案 0 :(得分:3)

在故事板中,选择要隐藏标签栏的视图控制器,转到属性检查器,然后在视图控制器部分&gt;中选择。 Extend Edges选择Under Bottom Bars下的复选框。

如果您的酒吧不透明,请选择Under Opaque Bars。

答案 1 :(得分:1)

使用此

-(void)viewWillAppear:(BOOL)animated
    {
        [self.navigationController setNavigationBarHidden:YES animated:animated];
        [self setHidesBottomBarWhenPushed:YES];
        [super viewWillApper:animated];
    }


        enter code here

    -(void)viewWillDisappear:(BOOL)animated
    {
        [self.navigationController setNavigationBarHidden:NO animated:animated];
        [self setHidesBottomBarWhenPushed:NO];
        [super viewWillDisapper:animated];
    }

答案 2 :(得分:0)

最佳答案,请在viewDidLoad中调用以下方法,并执行@tufyx推荐的操作!祝你好运

- (void)hideTabBar:(UITabBarController *)tabbarcontroller
{
    [tabbarcontroller.tabBar setHidden:YES];
    UIView *contentView;
    if ([[self.tableView.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]]) {
        contentView = [self.tableView.subviews objectAtIndex:1];
    } else {
        contentView = [self.tableView.subviews objectAtIndex:0];
    }
    contentView.frame = self.tableView.bounds;
}

答案 3 :(得分:0)

如果您使用像我这样的segues,那么您应该在推送之前设置视图控制器属性。这是一个很快的例子:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "YOUR_SEGUE_NAME" {
        let targetVC = segue.destinationViewController as! YOUR_VIEW_CONTROLLER
        targetVC.hidesBottomBarWhenPushed = true

    }