1

I created a ViewController with TableView inside it and embedded it a NavigationController. I also set the constraints. On Swipe down, Navigation Bar hides. Everything seems fine.

The only problem is that on Swipe Up, the Navigation Bar doesn't come back.

If I use the same TableView with a TableViewController instead of ViewController (embedded from the same Navigation Controller), the Navigation Bar does comes back.


For the ones wondering why I don't just go with the TableViewController, because I need to uncheck Adjust Scroll View Insets for some disturbing bug.

Community
  • 1
  • 1
senty
  • 12,385
  • 28
  • 130
  • 260

2 Answers2

3

To solve the issue, I used scrollViewWillEndDragging and detected 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
  • 12,385
  • 28
  • 130
  • 260
  • If you test for negative velocity, you can set a threshold speed to make the NavBar reappear. That way the user can control when the NavBar appears. – Bob Wakefield Oct 16 '16 at 16:12
1

Here's my solution, based on senty's answer:

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)
    }
}
Victor
  • 172
  • 1
  • 11