Xcode/iOS: How to hide Navigation- AND ToolBar on scroll down?

filou picture filou · Apr 16, 2012 · Viewed 18.8k times · Source

I would like to hide both bars on scroll down on my iPhone. When I scroll up, they should appear again.. How can I handle this?

Answer

mdominick picture mdominick · Apr 16, 2012
- (void)scrollViewWillBeginScroll :(UIScrollView *)scrollView {
      if (scrollView.contentOffset.y < lastOffset.y) {
                 [toolBar setHidden:YES];
                 [[[self navigationController] navigationBar] setHidden:YES];
      } else{
                 // unhide
      }
}

- (void)scrollViewDidScroll :(UIScrollView *)scrollView {
      /// blah blah
      lastOffset = scrollView.contentOffset;
}

Note : lastOffset is an CGPoint and it goes in your header file: @Interface.