uinavigationitem 每一个controller模型.
//self.automaticallyAdjustsScrollViewInsets=NO;//当vc的第一个subview为scrollview自动调整内边距
//self.tableView.frame= CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64-49);
//self.tableView.frame= CGRectMake(0, 64, SCREEN_WIDTH, self.view.sd_height-49);
//view-- {{0, 0}, {320, 519}}
//tableView -- {{0, 64}, {320, 455}}
//这个时候scrollview就穿透导航条
self.automaticallyAdjustsScrollViewInsets=YES;//当vc的第一个subview为scrollview自动调整内边距
//view-- {{0, 0}, {320, 519}}
//tableView -- {{0, 0}, {320, 519}}
contentOffset 负数: 超出原来的范围 是正数, 再范围内是负数。
[self.viewsd_logFrame:@"view"];//{{0, 0}, {320, 519}}
[self.tableViewsd_logFrame:@"tableView"];//{{0, 0}, {320, 519}}
NSLog(@"UIEdgeInsets::%@",NSStringFromUIEdgeInsets(self.tableView.contentInset));//{64, 0, 0, 0}
NSLog(@"contentOffset::%lf",self.tableView.contentOffset.y);//-64.000000
这句话会导致整个view从64开始算
//if ([self respondsToSelector:@selector(edgesForExtendedLayout)])// view {{0, 64}, {320, 455}}
//{
//self.edgesForExtendedLayout = UIRectEdgeNone;
//}
原来接口 那个宽度是ios 首页用的。
//===========================
1.NavigationItem存放在UINavigationBar上。由下图我们可以知道一个导航控制器控制着多个视图,一个视图控制器控制一个UINavigationItem。
2.UIViewController (UINavigationControllerItem) 添加扩展
UINavigationControllerItem 是属于uiviewcontroller。所以UINavigationController 也有这个属性。
3.研读UINavigationController Class Reference去,在“Updating the Navigation Bar”小节,有这么一段话:
The bar button item on the left side of the navigation bar allows for navigation back to the previous view controller on the navigation stack. The navigation controller updates the left side of the navigation bar as follows:
If the new top-level view controller has a custom left bar button item, that item is displayed. To specify a custom left bar button item, set the leftBarButtonItem property of the view controller’s navigation item.
If the top-level view controller does not have a custom left bar button item, butthe navigation item of thepreviousview controller has a valid item in itsbackBarButtonItemproperty, the navigation bar displays that item.
If a custom bar button item is not specified by either of the view controllers, a default back button is used and its title is set to the value of the title property of the previous view controller—that is, the view controller one level down on the stack. (If there is only one view controller on the navigation stack, no back button is displayed.)
我大致解释一下,使用pushViewController切换到下一个视图时,navigation controller按照以下3条顺序更改导航栏的左侧按钮。
1、如果B视图有一个自定义的左侧按钮(leftBarButtonItem),则会显示这个自定义按钮;
2、如果B没有自定义按钮,但是A视图的backBarButtonItem属性有自定义项,则显示这个自定义项;
3、如果前2条都没有,则默认显示一个后退按钮,后退按钮的标题是A视图的标题。
按照这个解释,我把UIBarButtonItem *backItem……这段代码放在A视图的pushViewController语句之前。
OK问题解决了,B视图的后退按钮的标题变成back了。
UIBarButtonItem*backItem=[[UIBarButtonItem alloc]initWithTitle:@"back"style:UIBarButtonItemStyleBordered target:nilaction:nil];
[self.navigationItem setBackBarButtonItem:backItem];
[backItem release];
[self.navigationController pushViewController:self.bView animated:YES];
4.UIBarMetrics
UIBarMetrics有点类似于按钮的for state状态,即什么状态下显示
//UIBarMetricsDefault-竖屏横屏都有,横屏导航条变宽,则自动repeat图片
//UIBarMetricsCompact-竖屏没有,横屏有,相当于之前老iOS版本里地UIBarMetricsLandscapePhone
//UIBarMetricsCompactPrompt和UIBarMetricsDefaultPrompt暂时不知道用处,官方解释是Applicable only in bars with the prompt property, such as UINavigationBar and UISearchBar,
5.去掉阴影
[self.navigationController.navigationBar setShadowImage:nil]; //无效
[self.navigationController.navigationBa rsetShadowImage:[[UIImagealloc]init]];//设置一个空的有效。
//背景设置nil系统自动帮你设置一张半透明的图片[self.navigationController.navigationBar setBackgroundImage:nilforBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setBackgroundImage:[[UIImagealloc]init]forBarMetrics:UIBarMetricsDefault];