UI基础学习之(十二):UINavigationController
2016-01-22 14:17
405 查看
UINavigationController
导航视图控制器,用来管理多个视图控制器,主要管理有层级关系的控制器。
UINavigationController继承于UIViewController,以栈的方式管理所控制的视图控制器,控制出栈和入栈来展示各个视图控制器。至少要有一个被管理的视图控制器,这个控制器我们称作,导航视图控制器的根视图控制器。
任何继承自UIViewController的类都可以作为根视图控制器。
UINavigationController的ContentView里始终显示栈顶控制器的View。
viewControllers属性存储课栈中的所有被管理的控制器。
通过navigationController属性(父类中的属性),每个在栈中的控制器,都能通过此属性,获取自己所在的UINavigationController对象,并进行push和pop。
pushViewController:<#(UIViewController*)#> animated:<#(BOOL)#>
进入下一个视图控制器,(将视图控制器拖入栈中)
popViewControllerAnimated:<#(BOOL)#>
返回上一个视图控制器
popToRootViewControllerAnimated:<#(BOOL)#>
返回到根视图控制器
popToViewController:<#(UIViewController*)#> animated:<#(BOOL)#>
返回到指定的视图控制器,栈中的视图控制器存储结构为数组,需要使用数组接收栈中的视图。
使用viewControllers属性,得到栈中的全部数组,index从0开始,设置指定视图的index后传入。
UIViewController * vc =self.navigationController.viewControllers[0];
[self.navigationController popToViewController:vc animated:YES];
出栈 pop 显示的视图并未出栈
可以接收视图,不接收的视图直接销毁,下次进入时重新创建。
只pop出栈顶的视图控制器
[self.navigationController popViewControllerAnimated:YES];
出栈 pop到指定的视图控制器ViewController
UIViewController * vc =self.navigationController.viewControllers[0];
[self.navigationController popToViewController:vc animated:YES];
出栈 pop到栈底位置
[self.navigationController popToRootViewControllerAnimated:YES];
常用属性:
viewControllers //所有处于栈中的控制器
topViewController //位于栈顶的控制器
visibleViewController //当前正在显⽰示的控制器
栈中的控制器(数组中顺序是按照入栈的顺序存储的)
NSLog(@"%@", self.navigationController.viewControllers);
栈顶视图控制器
NSLog(@"%@", self.navigationController.topViewController);
正在显示的视图控制器,一般来说是栈顶的视图控制器,但模态出来的视图控制器不入栈(正在显示,不位于栈顶)
NSLog(@"%@",self.navigationController.visibleViewController);
UINavigationBar 导航条
barTintColor //设置导航条的颜色
setBackgroundImage: forBarMetrics: //导航条加背景图片
设置 statueBar
竖屏:高度44 +statusBar 20
横屏:高度32
RootViewController * rootView = [[RootViewController alloc]init];
UINavigationController * rootNC = [[UINavigationController alloc]initWithRootViewController:rootView];
设置颜色
rootNC.navigationBar.barTintColor = [UIColor greenColor];
[rootNC.navigationBar setBackgroundImage:[UIImageimageNamed:@"01.png"] forBarMetrics:UIBarMetricsDefault];
self.window.rootViewController = rootNC;
UINavigationBar除了能定义自身的样式外,还管理一组UINavigationItem
与UINavigationController相似,UINavigationBar也是以栈的方式管理一组UINavigationItem。提供push和pop操作item。每个视图控制器都有一个navigationItem属性。
navigationItem中设置的左按钮、右按钮、标题等,会随着控制器的显示,也显示到navigationBar上。
UINavigationItem属于MVC中的M。封装了要显示在UINavigationBar上的数据。定义了UINavigationItem上按钮的触发事件,外观等。
title //标题
self.navigationItem.title = @"今日头条";
titleView //标题视图也可以添加label、button等View。
UITextField * textField = [[[UITextField alloc] init] autorelease];
textField.frame = CGRectMake(0, 0, 150, 34);
textField.borderStyle = UITextBorderStyleRoundedRect;
self.navigationItem.titleView = textField;
创建按钮使用的方法:
-initWithBarButtonSystemItem: target: action:
-initWithTitle: style: target: action:
-initWithImage: style: target: action:
tintColor// 按钮上文字显示的颜色
leftBarButtonItem //左按钮
当创建一个leftBarButton,会自动取代系统默认的backButton
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:selfaction:@selector(leftAction:)];
rightBarButtonItem //右按钮
UIBarButtonItem * bi1 = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStyleDone target:selfaction:@selector(bi1Action:)];
bi1.tintColor = [UIColor greenColor];
UIBarButtonItem * bi2 = [[UIBarButtonItem alloc]initWithTitle:@"好的" style:UIBarButtonItemStyleDone target:selfaction:@selector(bi2Action:)];
bi2.tintColor = [UIColor cyanColor];
self.navigationItem.rightBarButtonItems = @[bi2, bi1];
隐藏navigationBar会全部页面隐藏
self.navigationController.navigationBarHidden = YES;
添加隐藏时的动画
[self.navigationController setNavigationBarHidden:NO animated:YES];
UINavigationController的基类问题
创建时可以设置基类,设定基本的布局,其他的ViewController继承基类,完成初步的布局,不用单独设置。基类中的方法也能继承过去。
导航视图控制器,用来管理多个视图控制器,主要管理有层级关系的控制器。
UINavigationController继承于UIViewController,以栈的方式管理所控制的视图控制器,控制出栈和入栈来展示各个视图控制器。至少要有一个被管理的视图控制器,这个控制器我们称作,导航视图控制器的根视图控制器。
任何继承自UIViewController的类都可以作为根视图控制器。
UINavigationController的ContentView里始终显示栈顶控制器的View。
viewControllers属性存储课栈中的所有被管理的控制器。
通过navigationController属性(父类中的属性),每个在栈中的控制器,都能通过此属性,获取自己所在的UINavigationController对象,并进行push和pop。
pushViewController:<#(UIViewController*)#> animated:<#(BOOL)#>
进入下一个视图控制器,(将视图控制器拖入栈中)
popViewControllerAnimated:<#(BOOL)#>
返回上一个视图控制器
popToRootViewControllerAnimated:<#(BOOL)#>
返回到根视图控制器
popToViewController:<#(UIViewController*)#> animated:<#(BOOL)#>
返回到指定的视图控制器,栈中的视图控制器存储结构为数组,需要使用数组接收栈中的视图。
使用viewControllers属性,得到栈中的全部数组,index从0开始,设置指定视图的index后传入。
UIViewController * vc =self.navigationController.viewControllers[0];
[self.navigationController popToViewController:vc animated:YES];
出栈 pop 显示的视图并未出栈
可以接收视图,不接收的视图直接销毁,下次进入时重新创建。
只pop出栈顶的视图控制器
[self.navigationController popViewControllerAnimated:YES];
出栈 pop到指定的视图控制器ViewController
UIViewController * vc =self.navigationController.viewControllers[0];
[self.navigationController popToViewController:vc animated:YES];
出栈 pop到栈底位置
[self.navigationController popToRootViewControllerAnimated:YES];
常用属性:
viewControllers //所有处于栈中的控制器
topViewController //位于栈顶的控制器
visibleViewController //当前正在显⽰示的控制器
栈中的控制器(数组中顺序是按照入栈的顺序存储的)
NSLog(@"%@", self.navigationController.viewControllers);
栈顶视图控制器
NSLog(@"%@", self.navigationController.topViewController);
正在显示的视图控制器,一般来说是栈顶的视图控制器,但模态出来的视图控制器不入栈(正在显示,不位于栈顶)
NSLog(@"%@",self.navigationController.visibleViewController);
UINavigationBar 导航条
barTintColor //设置导航条的颜色
setBackgroundImage: forBarMetrics: //导航条加背景图片
设置 statueBar
竖屏:高度44 +statusBar 20
横屏:高度32
RootViewController * rootView = [[RootViewController alloc]init];
UINavigationController * rootNC = [[UINavigationController alloc]initWithRootViewController:rootView];
设置颜色
rootNC.navigationBar.barTintColor = [UIColor greenColor];
[rootNC.navigationBar setBackgroundImage:[UIImageimageNamed:@"01.png"] forBarMetrics:UIBarMetricsDefault];
self.window.rootViewController = rootNC;
UINavigationBar除了能定义自身的样式外,还管理一组UINavigationItem
与UINavigationController相似,UINavigationBar也是以栈的方式管理一组UINavigationItem。提供push和pop操作item。每个视图控制器都有一个navigationItem属性。
navigationItem中设置的左按钮、右按钮、标题等,会随着控制器的显示,也显示到navigationBar上。
UINavigationItem属于MVC中的M。封装了要显示在UINavigationBar上的数据。定义了UINavigationItem上按钮的触发事件,外观等。
title //标题
self.navigationItem.title = @"今日头条";
titleView //标题视图也可以添加label、button等View。
UITextField * textField = [[[UITextField alloc] init] autorelease];
textField.frame = CGRectMake(0, 0, 150, 34);
textField.borderStyle = UITextBorderStyleRoundedRect;
self.navigationItem.titleView = textField;
创建按钮使用的方法:
-initWithBarButtonSystemItem: target: action:
-initWithTitle: style: target: action:
-initWithImage: style: target: action:
tintColor// 按钮上文字显示的颜色
leftBarButtonItem //左按钮
当创建一个leftBarButton,会自动取代系统默认的backButton
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:selfaction:@selector(leftAction:)];
rightBarButtonItem //右按钮
UIBarButtonItem * bi1 = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStyleDone target:selfaction:@selector(bi1Action:)];
bi1.tintColor = [UIColor greenColor];
UIBarButtonItem * bi2 = [[UIBarButtonItem alloc]initWithTitle:@"好的" style:UIBarButtonItemStyleDone target:selfaction:@selector(bi2Action:)];
bi2.tintColor = [UIColor cyanColor];
self.navigationItem.rightBarButtonItems = @[bi2, bi1];
隐藏navigationBar会全部页面隐藏
self.navigationController.navigationBarHidden = YES;
添加隐藏时的动画
[self.navigationController setNavigationBarHidden:NO animated:YES];
UINavigationController的基类问题
创建时可以设置基类,设定基本的布局,其他的ViewController继承基类,完成初步的布局,不用单独设置。基类中的方法也能继承过去。
相关文章推荐
- C# 连接 mySQL 出现 GUID 应包含带 4 个短划线的 32 位数 问题
- 不错的UIPageControl替代控件TAPageControl
- poj 3080 Blue Jeans KMP多模式匹配
- Elasticsearch之query与filter
- uiviewcontroller 状态栏 self.view起始位置
- *Unique Combination of Factors (因式分解)
- Codeforces 441 B. Valera and Fruits
- HDU 1423 Greatest Common Increasing Subsequence(最长公共上升LCIS)
- Java序列化的作用serialVersionUID
- EasyUI自定义验证-ajax验证用户名是否可用,成功并跳转页面
- Android Bluetooth蓝牙开发:Bluetooth蓝牙设备之间数据传输(4)
- WebRequest使用 调用新浪天气
- Android 学习记录之requestWindowFeature属性解析
- 利用pageControl 来做自动轮播
- SoapUI读取外部excel数据以及script断言
- SoapUI自动化--Groovy脚本实现随机抽取DataSource(Excel)
- soapUI(groovy脚本作用1)请不要问为什么系列1
- SoapUI对于Json数据进行属性值获取与传递
- SoapUI命令行方式运行
- SoapUI用groovy脚本提取json数组数据