简体   繁体   English

iOS7无法隐藏标签栏,黑条

[英]iOS7 can not hide tabbar, black bar

I want to hide my tab bar when I scroll the collection view, code is 当我滚动集合视图时,我想隐藏我的标签栏,代码是

 #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;
}

but in iOS7 ,when tab bar is hidden , there is a black bar which does not dismiss. 但是在iOS7中,当标签栏被隐藏时,有一个黑色的栏不会消失。 How can I hide tabbar in iOS7? 如何在iOS7中隐藏标签栏?

In your storyboard, select the view controller for which you wish to hide the tab bar, go to attributes inspector, and in the View Controller section > Extend Edges choose the checkbox Under Bottom Bars. 在情节提要中,选择要为其隐藏标签栏的视图控制器,转到属性检查器,然后在“视图控制器”部分>“扩展边缘”中,选中“底部栏”下的复选框。

If your bar is opaque select also Under Opaque Bars. 如果您的条形图是不透明的,请同时选择“不透明条形图”。

use this 用这个

-(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];
    }

BEST ANSWER, call the following method at viewDidLoad and do what @tufyx recommended! 最佳答案,在viewDidLoad处调用以下方法并执行@tufyx建议的操作! Good Luck 祝好运

- (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;
}

If you are using segues like me then you should set the view controller property before push. 如果您正在使用像我这样的segues,则应在推送之前设置视图控制器属性。 Here is swift example : 这是迅速的例子:

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

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM