2016-05-12 47 views
0

Im使用帶有tableView的UIViewController。我已經設置了一個searchcontroller並將搜索欄嵌入到tableview標題中。當我搜索它時,會在桌面視圖和其上方的視圖之間留下狀態欄大小的差距。我意識到關於這個問題還有很多其他問題,但他們都沒有解決這個問題。在tableview標題中的UISearchController搜索欄留下狀態欄大小的差距

這裏是設置搜索欄的代碼:

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil]; 
self.searchController.searchResultsUpdater = self; 
self.searchController.dimsBackgroundDuringPresentation = NO; 
self.searchController.hidesNavigationBarDuringPresentation = YES; 
self.searchController.searchBar.delegate = self; 
self.searchController.searchBar.backgroundImage = [UIImage new]; 
self.searchController.searchBar.backgroundColor = kBlueNavBarColor; 
self.searchController.searchBar.tintColor = [UIColor whiteColor]; 

self.tableView.tableHeaderView = self.searchController.searchBar; 
self.definesPresentationContext = YES; 

enter image description here enter image description here Here is the layout of the view:

回答

0

我通過改變「頂部」自動佈局保持從「超級視圖」到「頂部佈局引導段控制器的視圖的錨固定它」。這將間隙拉到了狀態欄的位置,並將整個視圖的背景顏色更改爲與導航欄無縫相同的藍色。

0

呈現出UIViewController模態的時候我也有類似的問題。導航欄變得太過分了。我調整了導航欄的寬度。讓我知道這是否有幫助。這個問題從iOS 7開始。您可能不需要檢查版本。

float currentVersion = 7.0; 
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= currentVersion) { 
     // iOS 7 
     self.navBar.frame = CGRectMake(self.navBar.frame.origin.x, self.navBar.frame.origin.y, self.navBar.frame.size.width, 64); 
    } 
+0

謝謝,這是行不通的。 –

+0

當您調整導航欄的大小時,會發生什麼情況,灰色仍然稍微低一點? – Yan

+0

我想通了,看到我的答案。謝謝。 –

0

禁用大小類並定義自定義自動調整。請參考以下圖片: -

UITableView Autoresize:- 

Autoresizing for UITableView

UISearchBar Autoresize:- 

UISearchBarController autoresize

注:: - 你CA在禁用自動佈局和大小類時,請參閱上面的大小檢查器。

+0

關閉整個故事板的自動佈局來解決這個問題並不是真的可行。 –

+0

是的,我可以理解。 – MShah

0

enter image description here

取消選中調整滾動查看插圖

+0

試過這個,沒有工作 –