-1

I want to have search functionality similar to that of the instagram app. When editing begins in the search bar push a view controller and have the search bar filter that controller. However when I push a view controller, the navigation bar the search bar goes away and a back button is shown along with the new view.

Is it possible to

  1. push the view controller from the bottom of the screen
  2. keep the search bar from disappearing

Here's my func searchBarTextDidBeginEditing

func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
    let layout = UICollectionViewFlowLayout()

    let resultsController = ResultsController(collectionViewLayout: layout)

    navigationController?.pushViewController(resultsController, animated: true)

}
Stefan
  • 908
  • 1
  • 11
  • 33
  • Are you sure they push a view controller, as opposed to showing a part-sized view as an animated overlay? – Phillip Mills Jul 17 '17 at 19:15
  • 1
    Search bar coupled with view controller? Do you know about [UISearchController](https://developer.apple.com/documentation/uikit/uisearchcontroller)? – matt Jul 17 '17 at 19:16
  • Pushing the view controller from the bottom is not the default behavior of push action. It's presenting modal behavior. Still if you want to do it, you can make a custom animation class and change animation of push – Sivajee Battina Jul 17 '17 at 19:17
  • @matt does UISearchController show the search bar in the navigationbar? – Stefan Jul 17 '17 at 19:19
  • @SivajeeBattina I tried presenting a modal but it covers the navigation controller because it's full screen – Stefan Jul 17 '17 at 19:20

1 Answers1

0

I suggest putting the search bar as part of a parent ViewController and toggling between two child view controllers whenever the search bar is in use. This code shows how to add a child view controller to a parent. There are similar methods to removing it. This way you can choose which view controller you want to show in different scenarios.

self.addChildViewController(searchVC)
self.scrollView.addSubview(searchVC.view)
searchVC.didMoveToParentViewController(self)
clayjones94
  • 2,648
  • 17
  • 26