1,UINavigationController简介
导航控制器,ios常用
使用堆栈存储。根视图控制器在堆栈最底层。
[self.navigationController pushViewController:viewController animated:YES]; //入栈 进入viewController视图控制器 [self.navigationController popViewControllerAnimated:YES]; //出栈,返回上一个视图控制器 [self.navigationController popToViewController:UIViewController animated:YES]; //返回到指定的试图控制器 [self.navigationController popToRootViewControllerAnimated:YES]; //返回根控制器
2,UINavigationController的结构组成
UINavigationController由Navigation bar ,Navigation View ,Navigation toobar等组成;
3,UINavigationController的创建
UINavigationController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds]; self.window.backgroundColor = [UIColor groupTableViewBackgroundColor]; ViewController *rootVC = [[ViewController alloc] init]; UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController: rootVC]; [self.window setRootViewController: navigation]; [self.window makeKeyAndVisible]; return YES; }
4,UINavigationBar
(1)默认NavigationBar
navigationBar--导航条,iOS7以后默认是透明的,iOS7以前默认是不透明的。
navigationBar在透明情况下,与contentView会重合一部分区域
navigationBar在不透明情况,ContentView跟在navigationBar下面
navigationBar竖屏下默认高度44,横屏下默认高度32
(2)自定义NavigationBar
[self.navigationController.navigationBar setTranslucent: NO]; //显示出NavigationBar self.navigationController.navigationBar.backgroundColor = [UIColor redColor]; // 设置导航条的颜色 [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"tupianName"] forBarMetrics:UIBarMetricsCompact]; //导航条加背景图片
(3)自定义左侧按钮
- (void)viewDidLoad { [super viewDidLoad]; // 自定义导航栏左侧按钮 UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; leftBtn.frame = CGRectMake(0, 10, 93, 30); leftBtn.backgroundColor = [UIColor orangeColor]; [leftBtn addTarget:self action:@selector(onTap) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn]; self.navigationItem.leftBarButtonItem = leftItem; }
(4)自定义右侧按钮
与左侧按钮类似,区别在于:
self.navigationItem.rightBarButtonItem = rightItem;
(5)自定义中间视图
UIView * centerView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, 120, 30)]; centerView.backgroundColor = [UIColor greenColor]; self.navigationItem.titleView = centerView;
5,UINavigationToolbar
(1)显示Toolbar
[self.navigationController setToolbarHidden:NO animated:YES] ;
(2)在ToolBar上添加UIBarButtonItem
UIBarButtonItem *camera=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(ClickToolBarButton)]; [camera setWidth:80]; UIBarButtonItem *refresh=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(ClickToolBarButton)]; [refresh setWidth:80]; UIBarButtonItem *reply=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(ClickToolBarButton)]; [reply setWidth:80]; UIBarButtonItem *compose=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(ClickToolBarButton)]; [compose setWidth:80]; UIBarButtonItem *splitspace=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; [self setToolbarItems:[NSArray arrayWithObjects:splitspace,camera,splitspace,refresh,splitspace,reply,splitspace,compose,splitspace, nil nil]];
相关推荐
UINavigationController的一些使用详解
NULL 博文链接:https://android-zhang.iteye.com/blog/1756555
UITabBarController和UINavigationController的整合使用DEMO,详情见:http://blog.csdn.net/hwe_xc/article/details/50588500
iOS 使用UINavigationController 进行页面跳转 http://blog.csdn.net/liuyan20092009/article/details/52233769
我们写iOS项目的时候,基本都是一个UINavigationController套一个UITabBarController的形式,就是上面一个导航栏,下面几个按钮的工具条的形式。我写了几个应用,发现如果每次都重新写的话完全就是浪费精力和时间,...
上传的demo关于UINavigationController中back按钮的重写方法, UINavigationController的back按妞本身是没有监听方法的,但是我们通过添加类目可以使back按钮具有监听的作用.让我们能在UINavigationController触发返回...
UINavigationController 简单使用方法,增加自定义导航按钮。图片按钮,switch按钮。
swift5.0 UINavigationController基础使用, 新手自学练习
IOS7 UINavigationController滑动Demo,解决了在push后的页面可以滑动返回的问题。
UInavigationController笔记
页面跳转 UITabBarController+UINavigationController+UIViewController
导航控制器(UINavigationController)用来管理一系列显示层次型信息的场景。一般而言,逐步显示更详细的信息。 导航控制器 -- 用户在场景之间切换时,导航控制器依次将视图控制器压入(push)堆栈中,且当前场景的...
iOS UINavigationController自定义,push动画效果
一个小demo,演示如何隐藏tabbar
* 从iOS7开始,系统为UINavigationController提供了一个interactivePopGestureRecognizer用于右滑返回(pop),但是,如果自定了返回按钮或者隐藏了navigationBar,该手势就失效了。 ## 原因 * 自定义返回按钮或者隐藏...
让 UINavigationController 支持全屏操作手势.zip,A UINavigationController's category to enable fullscreen pop gesture with iOS7 system style.
UINavigationController导航控制器
相关知识共享: leftBarButtonItem与backBarButtonItem的区别 - http://blog.csdn.net/moon_prince2013/article/details/49079251 ViewController中[self setTtile]与[self.navigationItem setTitle]的... ... ...
很多时候我们创建一个基于UITabBarController的application以后还希望能够在每个tab view都可以实现导航控制,即添加一个UINavigationController来实现tabview内部的view之间的切换,这即是本文所要介绍的。
iphone中的基础控件UINavigationController,适合初学者,主要学习UINavigationController的基本属性和常用方法调用。 UINavigationController也是一种常用的容器,跟前边学过的tabbar差不多,在这个容器中可以添加...