1

I'm trying to implement the same behavior/functionality that instagram uses when scrolling through a tableview the navigation bar minimizes. I've researched this and utilized the solution found here:

Imitate iOS 7 Facebook hide/show expanding/contracting Navigation Bar

This solution is really useful but I'm running into a problem. I'm using a section header in section 0 of my tableView. When I scroll up, the navigation bar hides, but the tableView does not adjust its size for the navigation bar changes. This leaves a gap when the navigation bar collapses which looks like this:

Before scroll up

After scroll up

I've found other various articles online saying that this problem has to do with the contentInset of the tableView but I could not find more details on this. If anyone has any advice on how to fix this problem that would be awesome.

Community
  • 1
  • 1
zic10
  • 2,310
  • 5
  • 30
  • 55

3 Answers3

1

I think here's what you want, or you can put the to the header or row at index 0 of the tableView if it's a custom navigation bar, you can just hide the header row at index 0.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
     if(scrollView.contentOffset.y <= distance)
     {
         //scrollup

         [navigationController setNavigationBarHidden: NO animated:YES];
     }
     else if(scrollView.contentOffset.y >= distance)
     {
        //scrolldown
            [self.navigationController.navigationBar setItems:nil];
            [navigationController setNavigationBarHidden: YES animated:YES];
         }

}
0

You use yourTable/scrollToRowAtIndexPath. When go to indexPath difference first row -> hide navigation When go to first row -> show navigation

UITableView is a subclass of UIScrollView and table's delegate can also act as a scroll view's delegate. So you can use all methods from UIScrollViewDelegate for your table (implementing them in table's delegate), e.g.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
Vivek Molkar
  • 3,910
  • 1
  • 34
  • 46
Binladenit Tran
  • 121
  • 1
  • 1
  • 7
0

Why not use UINavigationController 's new property: hidesBarsOnSwipe?

childrenOurFuture
  • 1,889
  • 2
  • 14
  • 23