hController无法与非半透明的UINavigationB

hController无法与非半透明的UINavigationB

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

问题描述

目前我正在尝试将UISearchController嵌入到我的应用程序中。但是UISearchBar是UISearchController的一个属性,如果UINavigationBar是非半透明的,则无法正确显示。通常在点击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:

但如果是半透明属性UINavigationBar设置为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:

为了证明这种奇怪的行为,我修改了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.

推荐答案

这显然是一个错误(。

我的解决方法是设置

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一起正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 09:07