iOS 隐藏tabBar UITabBarController 以及 于UINavigationController 配合使用 push

来源:互联网 发布:win7 apache php 配置 编辑:程序博客网 时间:2024/06/05 13:35

关于隐藏tabBar底部的导航,模仿微信做法,主要用于方便在单独的页签可以一直push到下一个UIViewController;


布局:首先为一个UITabBarController

UITabBarController *tabBarController = [[UITabBarController alloc] init];


为tabBar增加4个对应的View;我们选择位UINavigationController ;

<pre name="code" class="objc">UITabBarController *tabBarController = [[UITabBarController alloc] init];    UserListViewController *userListVC = [[UserListViewController alloc] init];    DishListViewController *dishListVC = [[DishListViewController alloc] init];    FriendListController *friendListVC = [[FriendListController alloc] init];    WCIndexViewController *indexVC = [[WCIndexViewController alloc] init];                indexVC.title = @"index";    indexVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1];    [indexVC.tabBarItem setBadgeValue:@"1"];    //    indexVC.tabBarItem sett        userListVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:2];    userListVC.title = @"user";        dishListVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:5];    dishListVC.title = @"user";        friendListVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:4];    friendListVC.title = @"friend";        SJFanViewController *sjVC = [[SJFanViewController alloc] init];    UINavigationController *second = [[UINavigationController alloc] initWithRootViewController:sjVC];    second.title = @"second";    second.tabBarItem =[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:5];    second.tabBarItem.title = @"second";        UINavigationController *third = [[UINavigationController alloc] initWithRootViewController:userListVC];    third.title = @"third";    third.tabBarItem =[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:5];        UINavigationController *fourth = [[UINavigationController alloc] initWithRootViewController:friendListVC];    fourth.title = @"fourth";        NSArray *views = [NSArray arrayWithObjects: indexVC, second,third,fourth, nil];    //设置tabBar Item View    [tabBarController setViewControllers:views  animated:YES];        //默认显示哪个一个ViewController    [tabBarController setSelectedIndex:3];        tabBarController.tabBar.tintColor = [UIColor whiteColor];    //设置tabBar背景    tabBarController.tabBar.backgroundColor = [UIColor purpleColor];



我们暂时先选择第三个NaviGationController(rootController 是一个列表页面 或者个人信息页面) push进入下一个页签;

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{//    NSLog(@"%d",indexPath.row);    if(indexPath.section ==0){        NSLog(@"section 1");                //把当前页签设置push监控, 如果push,那么则隐藏tabBar导航栏        self.hidesBottomBarWhenPushed = YES;        UserInfoViewController *userInfo = [[UserInfoViewController alloc] init];                        [self.navigationController pushViewController:userInfo animated:YES];    }else if (indexPath.section == 1){        }    }

那么进入UserInfoController 之后,tabBar则隐藏了不会再现实出来,当点击back至前一个页面,tabBar也不会显示,我们得想办法让它显示出来;

则需要在当前的页面 

-(void) viewWillDisappear:(BOOL)animated{    self.hidesBottomBarWhenPushed = NO;}


以上变实现了tabBar隐藏及显示

主要是这句:

self.hidesBottomBarWhenPushed = YES;

self.hidesBottomBarWhenPushed = NO;







0 0
原创粉丝点击