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

编程入门 行业动态 更新时间:2024-10-26 21:26:36
本文介绍了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:

www.dropbox/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:

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

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

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

developer.apple/library/ios/samplecode/TableSearch_UISearchController/Introduction/Intro.html

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

Here you can download the modified version:

www.dropbox/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 一起正常工作

本文发布于:2023-10-30 18:52:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1543703.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:与非   工作   UISearchController   UINavigationBar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!