导航栏一旦隐藏(滑动)就不会回来

Navigation Bar doesn't come back once it hides (swipe)

我创建了一个 ViewController,其中包含 TableView,并将其嵌入了 NavigationController。我还设置了约束。向下滑动时,导航栏隐藏。一切似乎都很好。

唯一的问题是向上轻扫时,导航栏不会返回。

如果我将同一个 TableView 与 TableViewController 而不是 ViewController(从同一个导航控制器嵌入)一起使用,导航栏会返回。


对于那些想知道为什么我不直接使用表格的人ViewController,因为我需要取消选中 Adjust Scroll View Insets 以获得一些令人不安的

为了解决这个问题,我使用了 scrollViewWillEndDragging 并检测到 Going Down & Going Up

func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {

   if targetContentOffset.memory.y < scrollView.contentOffset.y {
       // UP
   } else {
       // DOWN
   }
}

这是我的解决方案,基于 senty 的回答:

func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {

    let draggDelta = scrollView.contentOffset.y - targetContentOffset.pointee.y

    let hiddenContentHeight = spreadsheetView.contentSize.height - spreadsheetView.frame.height - 1

    if 0 < draggDelta && targetContentOffset.pointee.y < hiddenContentHeight || (targetContentOffset.pointee.y == 0 && scrollView.contentOffset.y < 0) {

        // Shows Navigation Bar
        navigationController?.setNavigationBarHidden(false, animated: true)
    }
}