自 iOS 11 以来 RefreshControl 刷新后粘性 UINavigationbar

问题描述 投票:0回答:5

我们有一个使用两个导航层次结构的模块化应用程序,因此两个堆叠的导航栏...... 有时,当拉动刷新控件时,导航栏保持很大,并且在完成刷新后不会回落到正常大小。我只能猜测,在哪种情况下它会回落,而在哪种情况下它不会……可视化调试器显示,使用此空间的视图是一个

_UINavigationBarLargeTitleView
。在
viewDidLoad
中,
self.navigationController.navigationBar.prefersLargeTitles
设置为
NO

RefreshControl 通过以下方式添加到

viewDidLoad

self.refreshControl = [RefreshControl new];

我已经尝试过的一些事情:

  • 将 tableViews
    contentOffset
    设置为 (0,-1)。
  • 将prefersLargeTitles 设置为
    YES
    ,然后设置为
    NO
  • 设置 UINavigationControllers self.navigationItem。
    largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeNever;
    • 记录 UIRefreshControl 的不同状态:粘性视图和工作视图会产生相同的日志记录。

有人知道什么可能导致这个问题吗?正如我所说,我什至不确定这到底是什么时候发生,什么时候不发生......

ios uinavigationbar ios11 uirefreshcontrol
5个回答
6
投票

这个问题似乎只有在

navigationBar.isTranslucent == false
时才会发生。我需要这个设置来获得真正的 100% 黑色导航栏。

暂时我使用这个极其肮脏的黑客,受到异常答案的启发:

self.refreshControl?.endRefreshing()
if #available(iOS 11.0, *) {
    self.navigationController?.navigationBar.isTranslucent = true
    self.navigationController?.navigationBar.isTranslucent = false
}

1
投票

绝对是苹果的一个错误。除了下面的解决方法之外,无法使其工作。

tableView.reloadData {
    // Slightly scroll up, moving the navigation bar back to place
    self.tableView.setContentOffset(CGPoint(x: 0, y: -0.3), animated: false)
}

注意:必须在 tableView 重新加载之后并且没有动画。


0
投票

看起来这是苹果的一个错误。 试试这个

tableView.refreshControl?.endRefreshing()
//Because of a bug in iOS11 that leaves empty placeholder for refresh control
navigationController?.navigationBar.setNeedsLayout()
navigationController?.navigationBar.layoutIfNeeded()

也试试

navigationController?.navigationBar.appearance().isTranslucent = true


0
投票

此外,如果您的标题或第一个单元格变形,您可以添加此行:

tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: true)

它应该有助于以正常状态返回标题或单元格。完整的代码可能如下所示:

DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
   self.navigationController?.navigationBar.isTranslucent = true
   if self.refreshControl!.isRefreshing {
       self.refreshControl!.endRefreshing()
   }
   self.navigationController?.navigationBar.isTranslucent = false
   self.tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: true)
}

0
投票

就我而言,原因是我的

tableView.tableFooterView
tableView.reloadData()
设置为零。 所以我开始隐藏
tableView.tableFooterView
而不是将该视图设置为零,我的故障就消失了

© www.soinside.com 2019 - 2024. All rights reserved.