2017-01-06 21 views
2
func configureSearchController() { 
    // Initialize and perform a minimum configuration to the search controller. 
    searchController = UISearchController(searchResultsController: nil) 
    searchController.searchResultsUpdater = self 
    searchController.dimsBackgroundDuringPresentation = false 
    searchController.searchBar.placeholder = "Search" 
    searchController.searchBar.delegate = self 
    searchController.searchBar.sizeToFit() 

    // Add search bar to View. 
    self.view.addSubview(searchController.searchBar) 

    searchController.searchBar.translatesAutoresizingMaskIntoConstraints = false 

    view.bringSubview(toFront: searchController.searchBar) 

    //add constraints on searchbar 
    view.addConstraint(NSLayoutConstraint(item: searchController.searchBar, attribute: .trailing, relatedBy: .equal, toItem: view, attribute: .trailing, multiplier: 1, constant: 0)) 
    view.addConstraint(NSLayoutConstraint(item: searchController.searchBar, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1, constant: 0)) 

    view.addConstraint(NSLayoutConstraint(item: searchController.searchBar, attribute: .top, relatedBy: .equal, toItem: self.topLayoutGuide, attribute: .bottom, multiplier: 1, constant: 0)) 
    view.addConstraint(NSLayoutConstraint(item: searchController.searchBar, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute,multiplier: 1, constant: 64)) 

} 

私のコードだったので、searchController検索バーをサブビューとしてビューに追加しました。私も制約を加えました。UISearchBarを入力するときにUISearchControllerが表示されない理由を教えてください。

検索バーに何かを入力すると、全体が消え、ナビゲーションバーもアニメーション表示されます。

まず、それは次に、この So it looks like this

のように見える私は入力を開始するとき、 Poof It's gone

+0

そのa UISearchControllerのデフォルトの動作、Can uスクリーンショットを添付してください。 –

+0

この設定で再生しようとします。self.extendedLayoutIncludesOpaqueBars = trueまたはself.automaticallyAdjustsScrollViewInsets = true –

+0

動作しません –

答えて

0

searchController1.hidesNavigationBarDuringPresentationが= falseを

0

があなたのViewController

に以下を追加してしまっています
definesPresentationContext = true 
関連する問題