0

仅在使用 Xcode9 和 iOS 11 设备编译时发生。

部分标题不会自动粘在顶部,在视图中留下一个可以看到内容的空间。(包括屏幕截图)点击全屏时发生。但有时标题会在点击操作上粘在顶部 在
向上/向下滚动时,标题会粘在顶部。(包括 GIF)

截屏

动图

如果我错了,请纠正我,部分标题的浮动性质由 UITableViewStyle 设置为普通提供。

tableView = UITableView()
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 44
tableView.cellLayoutMarginsFollowReadableWidth = false
tableView = UITableView(frame: self.view.frame, style: UITableViewStyle.plain)
tableView.sectionHeaderHeight = 44
//    tableView.estimatedSectionHeaderHeight = 0
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "content")
tableView.register(UITableViewHeaderFooterView.self, forHeaderFooterViewReuseIdentifier: "hContent")
tableView.dataSource = self
tableView.delegate = self

尝试按照此处的建议将estimatedSectionHeaderHeight 设置为0(禁用它) 。但它没有用。

我们尝试按照此处针对类似问题的建议在我们的 hideNavBar 函数中重新加载 tableView 数据。但这会将我们滚动到其他内容。

按照我们 hideNavBar 函数中其他答案的建议尝试了以下操作,并再次面临我们滚动到一些遥远内容的相同问题。

tableView.reloadData()
tableView.layoutIfNeeded()
tableView.beginUpdates()
tableView.endUpdates() 
4

1 回答 1

0

这种变化可能是由于 iPhone X 的安全区域限制发生了变化。因此,我建议不要重新加载整个数据,而是为框架添加一个参考。即使在 iPhone X 中对我来说也很有效的解决方法。在相应的函数中添加以下行。

函数 hideNavbar() 和 hideTabbar()

tableView.frame = CGRect(x: 0, y: 0.01, width: view.bounds.width, height: view.bounds.height)

func showNavbar() 和 hideTabbar()

tableView.frame = CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height)
于 2018-02-24T06:25:17.167 回答