UINavigationController詳解

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];

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容