UINavigationController
UIViewController*vc = [[UIViewControlleralloc] init];
UINavigationController*nav = [[UINavigationControlleralloc] initWithRootViewController:vc];
self.window.rootViewController= nav;
底层实现
UINavigationController*nav = [[UINavigationControlleralloc] initWithRootViewController:vc];
UINavigationBar
设置标题
self.navigationItem.title = @"UINavigationBar
设置背景颜色
self.navigationController.navigationBar.barTintColor= [UIColorredColor];
设置背景图片
[self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"Background"] forBarMetrics:UIBarMetricsDefault];
设置返回按钮
self.navigationController.navigationBar.tintColor= [UIColorwhiteColor];
页面跳转
第一种类型:NavigationViewController跳转(右侧进入)
跳转:
//实例化一个将要跳转的viewControllerletsecondView =SecondViewController()
//跳转self.navigationController?.pushViewController(secondView , animated:true)
返回:(返回的方式有三种,下面会详细介绍)
//前提:确保当前ViewController是通过NavigationController的PushView方法跳转来的
//方式一:跳转到前一个页面self.navigationController?.popViewControllerAnimated(true)//实例化一个ViewControllerletfirstView =FirstViewController()//
方式二:返回至指定的ViewControllerself.navigationController?.popToViewController(viewController: firstView , animated:true)
//方式三:返回至最初的ViewController
//解释:通过pushView跳转firsView->secondView->thirdView,当在thirdView执行下面语句,则调回firtViewself.navigationController?.popToRootViewControllerAnimated(true)
第二种类型:ViewController跳转 (自下而上)
跳转
//实例化一个登陆界面letloginView =LoginViewController()
//从下弹出一个界面作为登陆界面,completion作为闭包,可以写一些弹出loginView时的一些操作self.presentViewController(loginView, animated:true, completion:nil)
返回
//前提:通过 View的presentViewController跳转的页面才能执行,否则找不到上一页
//同样可以执行关闭此页时的闭包操作self.dismissViewControllerAnimated(true, completion:nil)
模态
模态弹出
[[UIApplicationsharedApplication].keyWindow.rootViewControllerpresentViewController:showPicture animated:YEScompletion:nil];
SLoginRegisterViewController *loginVC = [[BSLoginRegisterViewController alloc] init]; [selfpresentViewController:loginVC animated:YEScompletion:nil];
模态返回
[selfdismissViewControllerAnimated:YEScompletion:nil];