隐藏tabbar

宓博实
2023-12-01


隐藏tabbar有两种方式:

1:在pushViewController之前调用

[self setHidesBottomBarWhenPushed:YES];

同时在viewWillDisappear调用:

- (void)viewWillDisappear:(BOOL)animated { 
    [self setHidesBottomBarWhenPushed:NO]; 
    [super viewDidDisappear:animated]; 
}

 

2:使用函数:

- (void) hideTabBar:(BOOL) hidden{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0]; 
    for(UIView *view in self.tabBarController.view.subviews) 
    { 
        if([view isKindOfClass:[UITabBar class]]) 
        { 
            if (hidden) { 
                [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)]; 
            } else { 
                [view setFrame:CGRectMake(view.frame.origin.x, 433, view.frame.size.width, view.frame.size.height)]; 
            } 
        } 
        else 
        { 
            if (hidden) { 
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)]; 
            } else { 
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 433)]; 
            } 
        } 
    } 
    [UIView commitAnimations]; 
}

方式一的方法代码简单,且界面也好控制一些

 类似资料: