嵌入导航栏时,iOS 7中的奇怪UISearchDisplayController视图偏移行为 [英] Strange UISearchDisplayController view offset behavior in iOS 7 when embedded in navigation bar

查看:94
本文介绍了嵌入导航栏时,iOS 7中的奇怪UISearchDisplayController视图偏移行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个仅限iOS 7的应用程序。我正在尝试将UISearchDisplayController设置到导航栏中。

I am building an iOS 7-only app. I am trying to set a UISearchDisplayController into the navigation bar.

我设置如下:在故事板中,我添加了搜索栏和搜索显示控制器到我的视图控制器的视图,并将其设置为(0,0)相对于顶部布局指南。我将约束设置为向左,向右和向右。 (我玩限制,我完全删除它们,没关系)最重要的是我有我的表视图。当我将搜索栏添加到故事板中的视图时,它会自动为searchDisplayController和searchBar委托设置插座。在代码中我有 self.searchDisplayController.displaysSearchBarInNavigationBar = YES; 我有两个问题:

I have it set up like this: In the storyboard, I added a "Search Bar and Search Display Controller" to my view controller's view, and set it at (0,0) relative to the top layout guide. I set constraints to pin to left, top and right. (I played with the constraints, i removed them completely, it doesn't matter) On top of that I have my Table view. When I added the search bar to the view in the storyboard, it automatically setup outlets for searchDisplayController and searchBar delegate. In code I have self.searchDisplayController.displaysSearchBarInNavigationBar = YES; I have two problems:

1)没有任何按钮显示搜索栏(界面构建器 - >选择搜索栏 - >选项:未选中)搜索栏位于屏幕中间:

1) Without any buttons showing for the search bar (Interface builder -> select search bar -> Options: none selected) the search bar is in the middle of the screen:

如果我点击导航栏,它开始编辑搜索栏:

If I click on the navigation bar, it starts editing the search bar:

还注意到暗覆盖图似乎偏离导航栏。在我看来,空间与导航栏的高度相同。就像它已经被那么多下降了。此外,当它显示搜索结果时,内容视图的顶部向下移动相同的数量(更多图片跟随),这带来了第二个问题。

notice also that the dark overlay appears to be offset from the navigation bar. It seems to me that the space is the same height as the navigation bar. Like it has been shifted down by that much. Also, when it displays the search results, the top of the content view is shifted down by the same amount (more pictures follow), which brings me to the second problem.

2)我搞砸了一会儿,决定检查选项让它显示取消按钮。现在我正确地在导航栏中嵌入了搜索栏,但叠加层仍然向下移动:

2) I messed around with it for a while and decided to check the option to have it show the cancel button. Now I have the search bar embedded in the nav bar correctly, but the overlay is still shifted down:

同样,当搜索结果表视图出现时,它会向下移动相同的数量(注意右侧的滚动条):

Again, when the search results table view appears, it is shifted down by the same amount (notice the scroll bar on the right side):

更奇怪的是,我在搜索显示控制器的tableview图层上设置了边框,看起来是正确的:

Even more bizarrely, I set a border on the search display controller's tableview layer, and it appears correct:

我以前从未使用过UISearchDisplayController而且我不熟悉如何设置它,但功能上它工作正常。我已经阅读了一些其他类似的帖子,但唯一的建议是通过调整帧和设置手动偏移来破解它。我更想知道造成这种情况的原因,这是一个错误吗?我做错了什么?如果这是一个错误我可以等待修复。看起来像一个基本的东西,千人一定没有任何问题,所以我觉得我不是以某种方式正确设置它。感谢您输入。

I have never used the UISearchDisplayController before and I unfamiliar with how to set it up, but functionally it works fine. I have read some other similar posts but the only advice is to hack it up by adjusting frames and setting manual offsets. I'd prefer to know what is causing this, is it a bug? Something I'm doing wrong? If it's a bug I can wait for a fix. It seems like such a basic thing that a thousand people must have done without any problem so I feel like I'm not setting it up correctly somehow. Thanks for you input.

推荐答案

我记得遇到了您正在观察的同样问题。可能有几个解决方案你可以试试。

I remember running into the same exact problem that you are observing.There could be a couple of solutions you can try.


  • 如果你使用的是故事板
    你应该点击您已经为tableview设置了视图控制器或TableView控制器,并转到其属性检查器并查看ViewController部分,并将Extend Edges部分设置为Top Bars。

  • If you are using storyboards You should click on the view controller or TableView Controller which you have set up for your tableview and go to its attribute inspector and look under ViewController section and set the Extend Edges section to be under Top Bars.

如果您没有使用故事板,您可以使用viewcontrollers edgesForExtendedLayout属性手动设置设置,这应该可以解决问题。我在使用故事板。

If you are not using storyboards you can manually set the settings using the viewcontrollers edgesForExtendedLayout property and that should do the trick. I was using storyboards.

这篇关于嵌入导航栏时,iOS 7中的奇怪UISearchDisplayController视图偏移行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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