1.描述
继承自UIViewController,依然是一种控制器,但是没有具体的view,是管理控制器的控制器
优点:能够管理和控制VC的走向,比present方式更清晰
2.创建
//创建导航控制器,将firstVc设置为导航控制器的根视图控制器
UINavigationController *navi=[[UINavigationController alloc]initWithRootViewController:firstVc];
3.方法
//firstVC 通知自己的导航控制器,推出视图 secondVC
[self.navigationController pushViewController:secondVC animated:YES];
//通知自己的试图控制器,返回上一张视图
[self.navigationController popViewControllerAnimated:YES];
4.代理方法
- (UIBarPosition)positionForBar:(id)bar{
return UIBarPositionTopAttached;
}
5.导航栏
5.1 配置
//获取导航栏
UINavigationBar *navi=self.navigationController.navigationBar;
//配置导航栏的背景色
navi.barTintColor=[UIColor redColor];
//配置导航栏是否透明为No
navi.translucent=NO;
//设置导航栏在默认状态下的背景图片
[navi setBackgroundImage:[UIImage imageNamed:@”NavigationBarDefault”] forBarMetrics:UIBarMetricsDefault];
//设置导航栏在横屏状态下的背景图片
[navi setBackgroundImage:[UIImage imageNamed:@”NavigationBarLandscapePhone”] forBarMetrics:UIBarMetricsLandscapePhone];
//设置返回按钮图片第二步
navi.backIndicatorTransitionMaskImage=[UIImage imageNamed:@”NavigationBarLandscapePhone”];
//设置返回按钮图片第一步
navi.backIndicatorImage=[UIImage imageNamed:@”NavigationBarLandscapePhone”];
//设置导航栏左右两边按钮的字的颜色
navi.tintColor=[UIColor redColor];
//设置title的属性
navi.titleTextAttributes=@{NSFontAttributeName: [UIFont systemFontOfSize:24],NSForegroundColorAttributeName:[UIColor redColor]};
5.2 属性
// 设置导航栏 title 显示 @” 小兔子系统 ”
self.title=@”小兔子系统”;
//创建一个导航栏按钮,当点击时,对象self实现方法goScondVC:
UIBarButtonItem *rightbutton=[[UIBarButtonItem alloc]initWithTitle:@“下一个” style:0 target:self action:@selector(goScondVC:)];
self.navigationItem.rightBarButtonItem=rightbutton;//将创建的导航栏按钮给导航栏
self.navigationItem.rightBarButtonItems=@[rightbutton1,rightbutton2];//将创建好的两个按钮给导航栏
5.3 方法
[self.navigationController setNavigationBarHidden:YES animated:YES];//设置导航栏隐藏为yes
6.工具栏
// 设置工具栏隐藏为 No ,范围为导航控制器管理的所有VC都生效
self.navigationController.toolbarHidden=NO;
//弹簧特效
UIBarButtonSystemItemFlexibleSpace
//木棍特效
UIBarButtonSystemItemFixedSpace
//设置按钮宽度
rightbutton2.width=40;
//设置在推出视图secondVC时,secondVC的底部的菜单栏是否隐藏
secondVC.hidesBottomBarWhenPushed=YES;