IOS Search bar that appears below navigation

放肆的年华 提交于 2019-12-12 06:43:26

问题


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

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.

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:

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

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?


回答1:


The long and short of this is that you can not do what I was attempting to do. You create a searchbar that when clicked transitions to a second screen with a searchbar in the header. This provides the cleanest experience compared to what I have listed above.



来源:https://stackoverflow.com/questions/37978399/ios-search-bar-that-appears-below-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!