第一节 UINavigationController
- UINavigationController基本知识
1>继承(UIViewController)
2>高度(64)
3>层级
2.UINavigationController创建
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
FirestViewController *firstVc = [[FirestViewController alloc] init]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:firstVc];(底层 [nav pushViewController:firstVc animated:YES];)
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
3.UINavigationController创建
//设置导航栏标题(导航控制器最顶层控制器)
self.navigationItem.title = @"第一个控制器";
//设置导航栏按钮内容文本
UIBarButtonItem *rightBarButtonIteam = [[UIBarButtonItem alloc] initWithTitle:@"右侧按钮" style:UIBarButtonItemStylePlain target:self action:@selector(rightClick)];
self.navigationItem.rightBarButtonItem = rightBarButtonIteam;
//设置导航栏按钮内容图片 iOS7之后,系统默认会把导航栏h上的图片渲染成蓝色,设置UIImage属性可以改变 UIImage *iteamImage = [UIImage imageNamed:@"icon-test-2"];
iteamImage = [iteamImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *leftBarButtonIteam = [[UIBarButtonItem alloc] initWithImage:iteamImage style:UIBarButtonItemStylePlain target:self action:@selector(leftClick)]; self.navigationItem.leftBarButtonItem = leftBarButtonIteam;
//自定义导航栏内容
UIImage *subIteamImage = [UIImage imageNamed:@"icon-test-3"];
subIteamImage = [subIteamImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIButton *leftButtonIteamCustom = [UIButton buttonWithType:UIButtonTypeCustom]; leftButtonIteamCustom.frame = CGRectMake(0, 0, 35, 35); [leftButtonIteamCustom setBackgroundImage:subIteamImage forState:UIControlStateNormal];
[leftButtonIteamCustom setBackgroundImage:iteamImage forState:UIControlStateHighlighted];
UIBarButtonItem *leftBarButtonIteamCustom = [[UIBarButtonItem alloc] initWithCustomView:leftButtonIteamCustom];
self.navigationItem.leftBarButtonItem = leftBarButtonIteamCustom;
第二节 UIViewController 的生命周期
1.storyboard创建UINavigationController\UIViewController以及导航栏内容的设置、控制器的跳转。
2.生命周期
/*ARC
控制器生命周期:viewDodload ->viewWillAppear->viewWillLayoutSubviews->viewDidLayoutSubviews->viewDidAppare->viewWillDisappear->viewDidDisappear
非ARC viewWillUnload->viewDidUnload
*/
//控制器的view加载完成的时候调用
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"%s",__func__);
}
//控制器view即将显示的时候调用
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSLog(@"%s",__func__);
}
//控制器view完全显示的时候调用
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
NSLog(@"%s",__func__);
}
//控制器view即将消失的时候调用
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
NSLog(@"%s",__func__);
}
//控制器view完全消失的时候调用
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
NSLog(@"%s",__func__);
}
//控制器view即将布局子控件的时候调用
-(void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
NSLog(@"%s",__func__);
}
//控制器view布局子控件完成的时候调用
-(void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
NSLog(@"%s",__func__);
}
//当前控制器收到内存警告的时候调用
-(void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
}
第四节微博个人信息案例
1.storyboard设置UINavigationController以及设置根控制器
2.storyboard设置UITableViewController控制器
3.设置tableview的透视图(tableHeaderView)
设置导航栏额外滚动区域
(if(@available(iOS 11.0, *)) {self.tableView.contentInsetAdjustmentBehavior= UIScrollViewContentInsetAdjustmentNever;
}else{self.automaticallyAdjustsScrollViewInsets= NO;})
4.设置导航栏自定义标题(titleView)
5.设置导航栏透明(
//设置导航栏透明[self.navigationController.navigationBarsetBackgroundImage:[UIImagenew] forBarMetrics:UIBarMetricsDefault];
//设置导航栏下划线透明
[self.navigationController.navigationBarsetShadowImage:[UIImagenew]];)