主要是UITabBarController和UINavigationController的组合实现功能:
appdelegate中代码如下:
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// ViewController *root = [[ViewController alloc]init];
// UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:root];
// self.window.rootViewController = nav;
TABViewController *tabBarController=[[TABViewController alloc]init];
MainViewController *main=[[MainViewController alloc]init];
MeViewController *me=[[MeViewController alloc]init];
//创建导航控制器nav1,显示firstView
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:main];
nav1.tabBarItem.title=@"react";
nav1.tabBarItem.image = [UIImage imageNamed:@"0.png"];
nav1.tabBarItem.selectedImage = [UIImage imageNamed:@"0.png"];
//创建导航控制器nav2,显示secondView
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:me];
nav2.tabBarItem.title=@"demo";
nav2.tabBarItem.image = [UIImage imageNamed:@"0.png"];
nav2.tabBarItem.selectedImage = [UIImage imageNamed:@"0.png"];
//给TabBarController控制器添加子控制器nav1
[tabBarController addChildViewController:nav1];
//给TabBarController控制器添加子控制器nav2
[tabBarController addChildViewController:nav2];
// tabBarController.viewControllers=@[webChatController,contactController];
//注意默认情况下UITabBarController在加载子视图时是懒加载的,所以这里调用一次contactController,否则在第一次展示时只有第一个控制器tab图标,contactController的tab图标不会显示
for (UIViewController *controller in tabBarController.viewControllers) {
UIViewController *view= controller.view;
}
_window.rootViewController=tabBarController;
[_window makeKeyAndVisible];
return YES;
}
MainViewController和MeViewController自行实现,MeViewController中我添加了一个navbarButton按钮进行页面跳转,代码如下:
MeViewController
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor whiteColor]];
// [self initNav];
self.navigationItem.title = @"小美的朋友圈";
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:@"跳转" style:UIBarButtonItemStyleDone target:self action:@selector(goto)];
self.navigationItem.leftBarButtonItem = btn;
-(void)goto{
DemoViewController *demo = [[DemoViewController alloc] init];
[self.navigationController pushViewController:demo animated:YES];
}
效果如下图:
跳转之后的界面:
跳转之后的界面要手动隐藏地步的tablebar;
-(instancetype)init{
// 使底部的TabBar隐藏
self = [super init];
if(self){
self.hidesBottomBarWhenPushed = YES;
}
return self;
}