IOS 搜索栏出现在导航下方 [英] IOS Search bar that appears below navigation

查看:41
本文介绍了IOS 搜索栏出现在导航下方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个搜索栏与显示在导航栏下方的 UISearchController 相关联,类似于:

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

目前,搜索栏替换了我见过的大多数/所有 IOS 应用程序中常见的标题.我尝试通过几种方法来控制搜索栏的显示:

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) 创建一个位于导航栏下方的新视图,并将 SearchController 的搜索栏分配给它.

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)

但是搜索栏显示在屏幕下方 1/2 处.

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

2)第二次尝试是将搜索栏的框架移动到原点:

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

最初看起来不错:

但是我一开始打字,栏又跳低了:

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

如何劫持 SearchController 以在导航栏中显示它的栏而不隐藏页面标题或限制搜索栏出现在导航栏正下方?

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?

推荐答案

总而言之,你不能做我试图做的事情.您创建一个搜索栏,单击该搜索栏时会转换到标题中带有搜索栏的第二个屏幕.与我上面列出的相比,这提供了最干净的体验.

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.

这篇关于IOS 搜索栏出现在导航下方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆