RefreshControl刷新后UINavigationbar粘滞自iOS 11

2w2cym1i  于 12个月前  发布在  iOS
关注(0)|答案(5)|浏览(104)

我们有一个模块化的应用程序使用两个导航层次结构,因此两个堆叠的导航栏.有时,当拉刷新控制导航栏保持大,并没有回落到正常大小后完成刷新。我只能猜测,在这种情况下,它会回落,而在这种情况下,它不会.在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的不同状态:粘滞视图和工作视图产生相同的日志记录。

有人知道是什么导致了这个问题吗?就像我说的,我甚至不确定这到底是什么时候发生的,什么时候不发生。

0tdrvxhp

0tdrvxhp1#

这个问题似乎只发生在navigationBar.isTranslucent == false时。我需要这个设置来获得一个真实的100%黑色的导航栏。
目前,我使用这个非常肮脏的黑客,灵感来自异常的答案:

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

oymdgrw72#

绝对是苹果的bug。无法使其工作,除了下面的工作区。

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

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

7vux5j2d

7vux5j2d3#

看起来像是苹果的bug。试试这个
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

fcg9iug3

fcg9iug34#

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

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)
}
yx2lnoni

yx2lnoni5#

在我的例子中,原因是使用tableView.reloadData()将nil设置为tableView.tableFooterView。所以我只是开始隐藏tableView.tableFooterView,而不是将nil设置为该视图,我的故障消失了

相关问题