Tencent / QMUI_iOS

QMUI iOS——致力于提高项目 UI 开发效率的解决方案
http://qmuiteam.com/ios
Other
7.07k stars 1.37k forks source link

[UIKit Bug] UITableView.estimatedRowHeight 大于0且列表内容不足一屏时,将 searchBar 作为 tableHeaderView,无法自动吸附 #1160

Open sclcoder opened 3 years ago

sclcoder commented 3 years ago

测试代码 官方的Demo https://github.com/QMUI/QMUIDemo_iOS

Bug 表现 QMUISearchController中的searchBar,激活再取消,searchBar的滚动范围变大了 跟踪代码发现以上操作导致tableView的contentSize大小发生变化。

截图 激活搜索前,向上滚动tableView,searchBar滚动到正确的位置,在导航条下方 Simulator Screen Shot - iPhone 11 - 2020-12-06 at 00 38 29

激活搜索然后又取消搜索,向上滚动tableView,searchBar不能滚到期望的位置,已被导航条挡住了 Simulator Screen Shot - iPhone 11 - 2020-12-06 at 00 38 42

这个效果和系统效果不一致

如何重现

  1. 点击searchBar变为激活状态 2.取消搜索,向上滚动tableView, 在cell不足一屏时,发现searchBar不能滚到正确位置

预期的表现 激活和取消searchBar在tableView中的滚动范围前后一致,特别是在cell不足一屏时。 和系统效果一致。

其他信息

MoLice commented 3 years ago

重新表述这个 issue: 系统的 UITableView.tableHeaderView 如果是一个 UISearchBar 的话,自带一个交互效果:当你将 searchBar 往 navigationBar 内滚动一点后松手,列表会自动往上吸附,将 searchBar 隐藏到 navigationBar 内,不管列表内容此时是否超过一屏。但发现 QMUI 的列表没有这个特性(例如 QDSearchViewController)。

MoLice commented 3 years ago

这是系统 bug,与是否触发搜索无关,只要满足以下两点的其中一点,就会出现:

  1. self.tableView.estimatedRowHeight 指定为一个大于 0 的值。
  2. 同时实现 tableView:viewForHeaderInSection:、tableView:heightForHeaderInSection:、tableView:viewForFooterInSection:、tableView:heightForFooterInSection:。

这是测试 Demo,注意代码里的注释: TestSearchBar.zip

在 QMUI 里,这两个条件分别在:

  1. 条件1在 UITableView+QMUI.m _qmui_configEstimatedRowHeight 方法里,会把 tableView.estimatedRowHeight 赋值为 TableViewCellNormalHeight,而 QD 里配置了这个宏的值为 56。
  2. 条件2在 QMUICommonTableViewController.m 里。
sclcoder commented 3 years ago

这是系统 bug,与是否触发搜索无关,只要满足以下两点的其中一点,就会出现:

  1. self.tableView.estimatedRowHeight 指定为一个大于 0 的值。
  2. 同时实现 tableView:viewForHeaderInSection:、tableView:heightForHeaderInSection:、tableView:viewForFooterInSection:、tableView:heightForFooterInSection:。

这是测试 Demo,注意代码里的注释: TestSearchBar.zip

在 QMUI 里,这两个条件分别在:

  1. 条件1在 UITableView+QMUI.m _qmui_configEstimatedRowHeight 方法里,会把 tableView.estimatedRowHeight 赋值为 TableViewCellNormalHeight,而 QD 里配置了这个宏的值为 56。
  2. 条件2在 QMUICommonTableViewController.m 里。

多谢,接手的新项目用的QMUI,查了好久不知道问题出在哪里。现在可算清楚了