2017-02-22 138 views
1

我有一個UISearchController,我用編程方式呈現時,用戶觸摸一個按鈕。我的問題是,搜索欄重疊的狀態(見截圖)呈現UISearchController與狀態欄重疊

enter image description here

我有以下的代碼,我用它來呈現UISearchController

func presentSearchController() { 
    let resultsController = ResultsViewController() 

    self.searchController = UISearchController(searchResultsController: resultsController) 
    self.searchController.searchBar.searchBarStyle = .prominent 

    searchController.hidesNavigationBarDuringPresentation = false 
    searchController.searchResultsUpdater = resultsController 

    self.definesPresentationContext = true 

    self.present(self.searchController, animated: true, completion: nil) 
} 

編輯:我的問題是不是重複UISearchBar overlaps status bar in iOS,因爲我不直接與搜索欄或它的框架

+0

它看起來就像你有一個從'CGRectMake地方搜索欄架(0 ,0,寬度,hright)'在th vc?對? –

+1

我在半個小時之前遇到了同樣的問題。 –

+0

@Mukesh我已經解決了這個問題。看到我的回答如下 – Lneuner

回答

4

我已經通過刪除以下行解決了該問題:

self.definesPresentationContext = true

這不是我的方案所需的原因是,我打電話self.present(self.searchController, animated: true, completion: nil)

UPDATE:

雖然上面沒有解決我的問題,它打破了在推的viewController的功能我的navigationController顯示SearchController時(searchController會保持在最前面,而viewController被推到它的下面)

在重新審視這個問題時,下面是我所做的修復:

然後添加以下

searchController.hidesNavigationBarDuringPresentation = true self.definesPresentationContext = true

至情節板中啓用「根據熱門酒吧」,並啓用「在不透明的酒吧」