UINavigationController总结
2015-11-23 18:37
411 查看
1.总述: 当我们利用UINavigationController的时候,无非就是利用其进行页面跳转。在这些页面跳转中, 当我们会遇到诸如:设置UINavigationBar中的内容、屏幕支持的方向等困难。 2.对导航控制器中的控制器的介绍: 1)UINavigationBar--导航条 1> ios7之前是不透明的,ios7之后是透明的。 2> navigationBar竖屏下默认高度是44,横屏下高度为32 2) UINavigationItem UINavigationBar能管理一组UINavigationItem,UINavigationBar也是通过栈的方式管理一 组UINavigationItem,提供push和pop操作item. 每个视图控制器都有一个navigationItem属性,navigationItem中设置的左按钮,右按钮,标题等会 随着控制器的显示也显示到navigationBar上。其属性为:title-->标题、titleView-->标题视图、 leftBarButtonItem,rightBarButtonItem 3) UIBarButtonItem 定义了UINavigationItem上按钮的触发事件,外观等。 - (instancetype)initWithImage:(UIImage *)image style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action; - (instancetype)initWithImage:(UIImage *)image landscapeImagePhone:(UIImage *)landscapeImagePhone style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action NS_AVAILABLE_IOS(5_0); // landscapeImagePhone will be used for the bar button image when the bar has Compact or Condensed bar metrics. - (instancetype)initWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action; - (instancetype)initWithBarButtonSystemItem:(UIBarButtonSystemItem)systemItem target:(id)target action:(SEL)action; - (instancetype)initWithCustomView:(UIView *)customView; 3.当一个控制器被push到一个navigationController中的时候,给控制器设置样式时可能会遇到的 困难: 1)设置UINavigationBar(导航条)的背景颜色: 在根控制器中设置---> self.navigationController.navigationBar.barTintColor = ? 2) 设置导航条为背景图片: 在根控制器中设置---> [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navback"] forBarMetrics:UIBarMetricsDefault]; 3)自定义leftBarButtonItem和rightBarButtonItem: 此时我们需要自己定义一个导航控制器去继承UINavigationControlelr,通过重写push方法来设置左右按钮 // 方法一:通过自定义button来进行 - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { if (self.viewControllers.count > 0) { // if the controller was pushed is not the first UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside]; [btn setBackgroundImage:[UIImage imageNamed:@"backItem"] forState:UIControlStateNormal]; [btn setBackgroundImage:[UIImage imageNamed:@"backItem"] forState:UIControlStateHighlighted]; btn.size = btn.currentBackgroundImage.size; viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn]; } [super pushViewController:viewController animated:animated]; } - (void)back { [self popViewControllerAnimated:YES]; } // 方法二: 通过定义UIBarButtonItem来进行 UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonItemTrash) target:nil action:nil]; self.navigationItem.rightBarButtonItem = rightBarButtonItem; 4) 当需要设置导航控制器不随屏幕旋转而旋转的时候,直接在根控制器中设置其是否支持旋转。
相关文章推荐
- easyUI 验证
- UIViewController的生命周期及iOS程序执行顺序
- CYC-关于UIImagePickerController
- Easyui datagrid editor为combobox时指定数据源
- 百度编辑器 多图片批量上传 顺序混乱问题 ueditor
- EasyUI----DataGrid行明细增删改操作
- reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier cellIdentifie
- Kibana User Guide [4.2] » Settings » Setting Kibana Server Properties
- [LeetCode] Range Sum Query - Mutable
- iOS-UIImage 互转 UIColor
- 二十六天( UI开始)
- iOS 【UIKit-UIPickerView】
- mrc下自定义UITableViewCell写法
- datagrid参数queryParams--easyUI
- EASYUI datagrid批量修改与提交
- Kibana User Guide [4.2] » Settings » Setting Advanced Options
- hdu5568 sequence2(dp + 高精度)
- UI复习
- [Qt]新增UAC功能之requireAdministrator
- iOS 9人机界面指南(一):UI设计基础