1.UINavigationController
UINavigationController(導(dǎo)航視圖控制器):管理控制器的控制器够委,主要管理有層次遞進(jìn)關(guān)系的控制器鄙币,以棧的方式管理所控制的視圖控制器,至少要由一個(gè)被管理的試圖控制器蹂随,這個(gè)視圖控制器叫導(dǎo)航視圖控制器的根視圖控制器
創(chuàng)建方法十嘿,在Appdelegate.m中創(chuàng)建
ViewController *VC = [[ViewController alloc] init];
UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:VC];
self.window.rootViewController = naVC;
2.UINavigationBar
UINavigationBar(導(dǎo)航欄):iOS7之后默認(rèn)是半透明,iOS7之前默認(rèn)是不透明的岳锁。豎屏下默認(rèn)高度44绩衷,橫屏下默認(rèn)高度32。iOS7之后激率,navigationBar的背景會(huì)延生到statusBar上咳燕,所以顯示效果為64。每個(gè)視圖控制器都有一個(gè)navigationItem屬性乒躺,在其中設(shè)置左按鈕招盲、右按鈕、標(biāo)題等聪蘸,會(huì)隨著控制器的顯示宪肖,也顯示到navigationBar上
導(dǎo)航欄屬性
self.navigationItem.title = @"標(biāo)題";// 創(chuàng)建單個(gè)titile
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];// 創(chuàng)建單個(gè)leftBarButtonItem
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save)];// 創(chuàng)建單個(gè)rightBarButtonItem
/*
// 創(chuàng)建多個(gè)titles
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"我", @"你"]];
segmentedControl.frame = CGRectMake(0, 0, 100, 30);
segmentedControl.selectedSegmentIndex = 0;
self.navigationItem.titleView = segmentedControl;
// 創(chuàng)建多個(gè)BarButtonItems
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save)];
self.navigationItem.leftBarButtonItems = @[item1, item2];
self.navigationItem.rightBarButtonItems = @[item1, item2];
// UINavigationBar屬性
self.navigationController.navigationBarHidden = NO;// 顯隱性
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;// 樣式
self.navigationController.navigationBar.backgroundColor = [UIColor redColor];;// 背景顏色
//self.navigationController.navigationBar.barTintColor = [UIColor yellowColor];// 前景顏色
self.navigationController.navigationBar.tintColor = [UIColor blackColor];// 元素顏色
*/
/**
* 半透明效果開(kāi)啟時(shí),坐標(biāo)原點(diǎn)為(0, 0)
半透明效果關(guān)閉時(shí)健爬,坐標(biāo)原點(diǎn)為(64, 0)
*/
self.navigationController.navigationBar.translucent = YES;// 半透明效果控乾,iOS7以后默認(rèn)為YES
3.頁(yè)面跳轉(zhuǎn)
導(dǎo)航視圖控制器push
- (void)add {
BlueViewController *blueVC = [[BlueViewController alloc] init];
[self.navigationController pushViewController:blueVC animated:YES];// 使用導(dǎo)航視圖控制器推出blueVC
}
模態(tài)推出
- (void)save {
BlueViewController *blueVC = [[BlueViewController alloc] init];
[self presentViewController:blueVC animated:YES completion:nil];// 模態(tài)推出blueVC
}
返回方法
- (void)back {
//[self.navigationController popToRootViewControllerAnimated:YES];// 返回根視圖控制器
//[self.navigationController popViewControllerAnimated:YES];// 返回上一個(gè)視圖控制器
[self dismissViewControllerAnimated:YES completion:nil];// 模態(tài)返回上一頁(yè)
}