#Objective - C - UI-design - 第七天 -UIKit框架-UIKit-导航控制器-UINavigationController
2016-01-11 09:32
866 查看
UINavigationController
UINavigationController:导航控制器,是iOS中最常用的多视图控制器之一,用它来管理多个视图控制器。导航控制器可以称为是,管理控制器的控制器,主要管理有层 次递进关系的控制器。
效果:
UINavigationController继承于UIViewController以栈的方式管理所控制的视图控制器,至少要有一个被管理的视图控制器:这个控制器我们称作,导航控制器的根视图控制器。
任何继承⾃自UIViewController的类(多态)都可以作为根控制器。
创建(Delegate.m下)
// 创建根视图 RootViewController *rootVC = [[RootViewController alloc] init]; // 创建导航控制器 把rootVC作为导航控制器的根视图控制器 UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:rootVC]; // 设置导航为window的根视图 self.window.rootViewController = navi; // 内存管理 [rootVC release]; [navi release];
UINavigationBar
UINavigationBar(导航栏)上的设置主要分两部分,一为导航栏上的各种导航部件(UINavigationItem),二为导航栏自身的相关设置。UINavigationBar—导航条,iOS7之后默认是半透明的,iOS7之前默认是不透明的。
UINavigationBar竖屏下默认高度44,横屏下默认高度32。
iOS7之后,UINavigationBar的背景会延伸到statusBar上。导航栏高度仍保持44,但显⽰示效果为64。
每个视图控制器都有一个UINavigationItem属性。UINavigationItem中设置的左按钮、右按钮、标题等,会随着控制器的显示,也显示到UINavigationBar上。
初始化
// 导航栏标题 self.title = @"标题"; // self.title会同时改变导航栏的标题和tabBar的标题 可以用如下方法单独操作导航栏标题 self.navigationItem.title = @"标题"; // 左按钮 self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(leftAction)] autorelease]; // 右按钮 self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage: [UIImage imageNamed:@"next"] style:UIBarButtonItemStylePlain target:self action:@selector(rightAction:)] autorelease];
属性:
// 导航栏的显隐属性 self.navigationController.navigationBarHidden = NO; // 导航栏样式 self.navigationController.navigationBar.barStyle = UIBarStyleDefault; // 背景颜色 self.navigationController.navigationBar.backgroundColor = [UIColor redColor]; // 导航栏颜色 self.navigationController.navigationBar.barTintColor = [UIColor yellowColor]; // 导航栏元素颜色 self.navigationController.navigationBar.tintColor = [UIColor blackColor];
UINavigationItem
// 按钮对象 UIBarButtonItem *item1 = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(leftAction)] autorelease]; UIBarButtonItem *item2 = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(leftAction)] autorelease]; // 左按钮数组 self.navigationItem.leftBarButtonItems = @[item1, item2]; // 右按钮数组 self.navigationItem.rightBarButtonItems = @[item1, item2];
TitleView标题视图
// 标题视图 titleView // 创建要添加的视图对象 UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"已接来电",@"未接来电"]]; // 设置属性 seg.frame = CGRectMake(0, 0,100, 30); seg.selectedSegmentIndex = 0; // 放在titleView上 self.navigationItem.titleView = seg; [seg release];
// 当半透明效果开启时 屏幕左上⾓角为坐标原点 // 关闭时 导航栏左下⾓角为坐标原点 self.navigationController.navigationBar.translucent = YES;
导航常用属性
入栈和出栈
//进入下一页 - (void)next { // 页面跳转 // 推出(push) // 1.创建第二页对象 SecondViewController *secVC = [[SecondViewController alloc] init]; // 2.通过导航控制器推出新的⻚页⾯面 [self.navigationController pushViewController:secVC animated:YES]; // 3.内存管理 [secVC release]; } //返回上一页 - (void)back { [self.navigationController popViewControllerAnimated:YES]; } // VC数组 NSLog(@"%@", self.navigationController.viewControllers); // 返回指定的VC [self.navigationController popToViewController:self.navigationController.viewControllers[0] animated:YES]; // 返回根视图 [self.navigationController popToRootViewControllerAnimated:YES];
小练习
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- jquery实现的蓝色二级导航条效果代码
- jQuery实现的导航条切换可显示隐藏
- jquery 导航条的效果(css选择器控制)
- 讲解iOS开发中基本的定位功能实现
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- 浅析iOS应用开发中线程间的通信与线程安全问题
- 检测iOS设备是否越狱的方法
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解
- Bootstrap每天必学之导航条
- JS实现选中当前菜单后高亮显示的导航条效果