UISearchController 不能与非半透明 UINavigationBar 一起正常工作

UISearchController doesn#39;t work properly with a non-translucent UINavigationBar(UISearchController 不能与非半透明 UINavigationBar 一起正常工作)

本文介绍了UISearchController 不能与非半透明 UINavigationBar 一起正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在尝试将 UISearchController 嵌入到我的应用程序中.但是,如果 UINavigationBar 不透明,作为 UISearchController 的属性的 UISearchBar 将无法正确显示.通常在点击 UISearchBar 属性后,UINavigationBar 会向上移动以为 UISearchBar 腾出空间.您可以在以下屏幕截图中看到结果:

Currently I am trying to embed a UISearchController into my application. But the UISearchBar, which is a property of the UISearchController, doesn't get displayed properly, if the UINavigationBar is non-translucent. Usually after tapping the UISearchBar property, the UINavigationBar moves up to make room for the UISearchBar. You can see the result on the following screenshot:

https://www.dropbox.com/s/172k63zr2bhj84t/Normal_behaviour.png?dl=0

但如果 UINavigationBar 的translucent"属性设置为NO",则 UISearchBar 无法正常显示,因为状态栏的背景保持透明,如下图所示:

But if the "translucent" property of the UINavigationBar is set to "NO", the UISearchBar doesn't get displayed properly, because the background of the status bar remains transparent, as you can see on the following screenshot:

https://www.dropbox.com/s/v5cnxoj9ms6976r/Wrong_behaviour.png?dl=0

为了演示这种奇怪的行为,我修改了 Apple 提供的示例项目:

To demonstrate this weird behaviour, I have modified the sample project provided by Apple:

https://developer.apple.com/library/ios/samplecode/TableSearch_UISearchController/Introduction/Intro.html

在这里你可以下载修改后的版本:

Here you can download the modified version:

https://www.dropbox.com/s/7icfe6kap98g1e8/TableSearchwithUISearchControllerObj-CandSwift_MODIFIED.zip?dl=0

修改在文件APLMainTableViewController.m"第33行.

The modification is in file "APLMainTableViewController.m" line 33.

推荐答案

这显然是一个错误 (rdar://20942583).

It's clearly a bug (rdar://20942583).

我的解决方法是设置

self.edgesForExtendedLayout = UIRectEdgeAll;
self.extendedLayoutIncludesOpaqueBars = YES;

这允许您保持导航栏不透明.缺点是即使看不到,内容也会在栏下方流动,从而产生一些开销.

This allows you to keep the navigation bar opaque. The downside is that the content flows below the bar even if it can't be seen, creating some overhead.

这篇关于UISearchController 不能与非半透明 UINavigationBar 一起正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:UISearchController 不能与非半透明 UINavigationBar 一起正常工作

基础教程推荐