2016-08-18 172 views
1

我使用UISearch欄控制器 enter image description here搜索欄按搜索後消失

我按下它後消失這樣 enter image description here

我的代碼:

let searchController = UISearchController(searchResultsController: nil) 


override func viewDidLoad() { 
    super.viewDidLoad() 

    // MARK: - Search 
    searchController.searchBar.delegate = self 
    navigationItem.titleView = searchController.searchBar 

} 
func searchBarTextDidBeginEditing(searchBar: UISearchBar) { 
presentViewController(searchController, animated: true, completion: nil) 

} 
+0

你爲什麼要叫 「presentViewController(searchController,動畫:真,完成:無)」 文本確實開始編輯...? –

+1

@羅伊克即使如果我不叫它我有同樣的問題 – Sam

回答

1

試試這個

self.searchController.hidesNavigationBarDuringPresentation = NO 
self.definesPresentationContext = NO 

或使用該

func willPresentSearchController(searchController: UISearchController)  { 
self.navigationController.navigationBar.translucent = true 
} 

func willDismissSearchController(searchController: UISearchController) { 
self.navigationController.navigationBar.translucent = false 
} 

額外的幫助看到這個link

0

嘗試設置該屬性Viewcontroller

self.definesPresentationContext = NO 
+0

不工作... – Sam