2016-11-22 129 views
0

這個問題基本上是這樣的,UISearchBar在激活時與狀態欄重疊。我知道已經發布了許多類似的問題,並且我嘗試了所有方法,但仍然無法解決問題。UISearchBar背景中額外的空間導致UISearchBar與狀態欄重疊

初始化屏幕時,搜索欄似乎處於正確的位置。當我向下滾動屏幕時,可以看到搜索欄的背景比我從iPhone上的郵件應用程序獲得的背景更高。

When screen is scrolled down a bit

在搜索欄背景的額外空間的高度是一樣的狀態欄的高度。我相信這是導致以下問題的原因,即當搜索欄被激活時,它與狀態欄重疊。但是,當搜索取消時,它將放回正常位置,如第一張圖所示。

Search bar overlaps with status bar when activated.

這是我的代碼。

全局變量:

let searchController = UISearchController(searchResultsController: nil) 

在viewDidLoad中:

self.extendedLayoutIncludesOpaqueBars = true 
    self.definesPresentationContext = true 
    self.navigationController?.navigationBar.isHidden = false 
    self.originalFrame = self.tabBarController?.tabBar.frame 
    searchController.hidesNavigationBarDuringPresentation = true 
    searchController.searchBar.barTintColor = Settings.tealColor 
    searchController.searchResultsUpdater = self 
    searchController.dimsBackgroundDuringPresentation = false 
    searchController.searchBar.scopeButtonTitles = ["All", "Pre-order", "Delivery", "Carry-out", "Dine-in", "History"] 
    searchController.searchBar.delegate = self 
    searchController.searchBar.sizeToFit() 
    restaurantTableView.tableHeaderView = searchController.searchBar 

你的任何幫助,將不勝感激。我已經在這個問題上工作了兩天。謝謝

回答

0

有趣的是,在我發佈了兩天的問題之後30分鐘,我自己就明白了這一點。罪魁禍首是我從定製導航欄切換到內置導航欄後沒有刪除的以下代碼塊。

func position(for bar: UIBarPositioning) -> UIBarPosition { 
    return UIBarPosition.topAttached 
} 

感謝您的關注,無論如何。希望有同樣問題的人可以在這裏受益。