UISearchController doesn#39;t work properly with a non-translucent 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 一起正常工作
- android 4中的android RadioButton问题 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01