vendredi 24 juin 2016

IOS Search bar that appears below navigation


I am attempting to have a search bar tied to my UISearchController that appears below the navigation bar, similar to this:

enter image description here

Currently the search bar replaces the title as is common in most/all IOS apps I've seen. I've attempted to control the search bar presentation through a few methods:

1) Creating a new view that sits underneath the nav bar, and assigning the SearchController's search bar to it.

//instead of:
//navigationItem.titleView = searchBar
//do this:
searchplaceholder.addSubview(searchBar)

However the search bar shows up 1/2 way down the screen.

enter image description here

2)Second attempt was to move the frame of the search bar to origin:

searchBar.frame = CGRectMake(0, 0, self.view.frame.width, searchBar.frame.height)
view.addSubview(searchBar)
resultSearchController?.active = true

Looks good initially:

enter image description here

But as soon as I start typing, the bar jumps low again:

enter image description here

How can i Hijack the SearchController to present it's bar either in the nav bar without hiding the page title or constrain the search bar to appear right under the nav bar?


Aucun commentaire:

Enregistrer un commentaire