1
//1.設置self.tabBarController.tabBar.hidden=YES;
self.tabBarController.tabBar.hidden=YES;
//2.如果在push跳轉時需要隱藏tabBar,設置self.hidesBottomBarWhenPushed=YES;
self.hidesBottomBarWhenPushed=YES;
NextViewController *next=[[NextViewController alloc]init];
[self.navigationController pushViewController:next animated:YES];
self.hidesBottomBarWhenPushed=NO;
//并在push后設置self.hidesBottomBarWhenPushed=NO;
//這樣back回來的時候,tabBar會恢復正常顯示。
2
Iphone隱藏和顯示TabBar的方法
1.隱藏TabBar:
- (void)hideTabBar {
if (self.tabBarController.tabBar.hidden == YES) {
return;
}
UIView *contentView;
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];
contentView.frame = CGRectMake(contentView.bounds.origin.x, contentView.bounds.origin.y, contentView.bounds.size.width, contentView.bounds.size.height + self.tabBarController.tabBar.frame.size.height);
self.tabBarController.tabBar.hidden = YES;
}
2.顯示TabBar:
- (void)showTabBar
{
if (self.tabBarController.tabBar.hidden == NO)
{
return;
}
UIView *contentView;
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];
contentView.frame = CGRectMake(contentView.bounds.origin.x, contentView.bounds.origin.y, contentView.bounds.size.width, contentView.bounds.size.height - self.tabBarController.tabBar.frame.size.height);
self.tabBarController.tabBar.hidden = NO;
}
3.如果定義了上面兩個方法,在viewDidAppear:方法里面就可以調用了
-(void)viewDidAppear:(BOOL)animated{
//[self hideTabBar];
[self showTabBar];
}
3
兩種方法用來隱藏tabBar
1.在本頁面隱藏
#pragma mark - 隱藏tabBar
- (void)viewWillAppear:(BOOL)animated{
** self.tabBarController.tabBar.hidden = YES;**
}
- (void)viewWillDisappear:(BOOL)animated{
** self.tabBarController.tabBar.hidden = NO;**
}
2.再跳界面之前設置跳轉后隱藏tabBar
#pragma mark - 隱藏tabBar
- (void)handleClickTestButtonAction:(UIButton *)sender{
SecurityTestingViewController *test = [[SecurityTestingViewController alloc]init];
**self.hidesBottomBarWhenPushed = YES;**
[self.navigationController pushViewController:test animated:NO];
}
4
//在項目中經常遇到隱藏tabBar,實力很多種方法,可以解決不同情況下問題
//1://隱藏tabBar
WebViewController *webVc = [[WebViewController alloc] init];
webVc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:webVc animated:YES];
webVc.hidesBottomBarWhenPushed = NO;
[webVc release];
//2.系統方法
self.hidesBottomBarWhenPushed = YES;
//3:自定義tabBar時候,由tabBarController管理的
//隱藏tabBar
- (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, iphone5?568:480, view.frame.size.width, view.frame.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, iphone5?568-49:480-49, 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, iphone5?568:480)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, iphone5?568-49:480-49)];
}
}
}
[UIView commitAnimations];
}
//調整子視圖
for (UIView *subView in self.view.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"UITransitionView")]) {
// 調整子視圖的高度,UITransitionView視圖為UINavitaionController的根視圖
subView.frame = CGRectMake(subView.frame.origin.x, subView.frame.origin.y, subView.frame.size.width, 480);
CGRect frame = subView.frame;
frame.size.height = 480;
subView.frame = frame;
}
}
//4:類似方法3
- (void)makeTabBarHidden:(BOOL)hide{
if ([self.tabBarController.view.subviews count] < 2) {
return;
}
UIView *contentView;
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;
}