【发布时间】:2020-02-24 16:03:50
【问题描述】:
我在FirstViewController 的navigationItem 中有一个UISearchController。在SecondViewController 中也是如此,我从FirstViewController 推送SecondViewController。
当用户滑动返回时,下面的 UI 故障是可见的。
包含UISearchController 的区域变暗。如果用户返回FirstViewController,它看起来不错。但是如果用户在滑动一点之后停留在SecondViewController,那么就是这个样子了。
拥有searchController 的空间现在是空的。如果用户向上或向下滚动,searchController 将再次可见。
选项试图解决问题
- 使用
UITableViewController代替UIViewController和UITableView - 在
viewDidLoad和viewWillAppear中切换navigationItem.hidesSearchBarWhenScrolling属性 - 在
viewWillDisappear中将navigationItem.searchController设置为nil
除了这个问题,当我在UIViewController 中使用UITableView 时,searchController 隐藏在标题下方,并且比消息、邮件等本机应用程序的输出速度略高。
当我使用UITableViewController 时,动画很流畅,但如果用户没有完全向上或向下滑动,则 searchController 会被击中,如下所示。无论有没有大标题,都会发生这种情况。
我的用例也可以实现,如果有人可以回答this question。
更新:
在SecondViewController 中将extendedLayoutIncludesOpaqueBars 设置为true 确实解决了这个问题。但是如果用户滑动返回但随后改变了他/她的想法,那么 tableview 中会有一个轻微的不受欢迎的混蛋。
【问题讨论】:
标签: ios swift uinavigationcontroller uikit uisearchcontroller