简体   繁体   English

导航下方显示的iOS搜索栏

[英]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: 我正在尝试将一个搜索栏绑定到出现在导航栏下方的UISearchController上,类似于:

在此处输入图片说明

Currently the search bar replaces the title as is common in most/all IOS apps I've seen. 目前,搜索栏将替换标题,这是我所见过的大多数/所有IOS应用程序中常见的标题。 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. 1)创建一个位于导航栏下方的新视图,并为其分配SearchController的搜索栏。

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

However the search bar shows up 1/2 way down the screen. 但是,搜索栏显示在屏幕下方1/2处。

在此处输入图片说明

2)Second attempt was to move the frame of the search bar to origin: 2)第二次尝试是将搜索栏的框架移至原点:

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? 我该如何劫持SearchController以在导航栏中显示其栏而不隐藏页面标题或限制搜索栏显示在导航栏的正下方?

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. 与我上面列出的相比,这提供了最干净的体验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM