1

Trying to make it so that when a user scrolls my application the navigation bar disseapears but when they scroll up it reappears.

I have the following code:

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    self.latestOffset = scrollView.contentOffset.y;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

   if(self.latestOffset > scrollView.contentOffset.y) {
       [self.navigationController setNavigationBarHidden:NO animated:YES];
   }

   if (self.latestOffset < scrollView.contentOffset.y) {
       [self.navigationController setNavigationBarHidden:YES animated:YES];
   }
}

Running into an issue where the navigation bar sometimes covers my scroll view and also an issue where if you don't scroll down far enough things seem to go wrong.

ComeOncOME
  • 11
  • 1
  • did you set up layout constraints? you need to adjust your scroll view size when the nav bar appears/disapears – nielsbot Jul 30 '15 at 17:34
  • How do I do that? @nielsbot – ComeOncOME Jul 30 '15 at 17:34
  • big topic. check Apple's docs or a tutorial. e.g. http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1 – nielsbot Jul 30 '15 at 17:40
  • possible duplicate of [Imitate iOS 7 Facebook hide/show expanding/contracting Navigation Bar](http://stackoverflow.com/questions/19819165/imitate-ios-7-facebook-hide-show-expanding-contracting-navigation-bar) – Benjamin Jimenez Jul 30 '15 at 17:53

1 Answers1

1

iOS 8 had some new interactions with navigation bar including 'hidesBarsOnSwipe'.

You can set that property and OS will automatically manage it for you,

navigationBar.hidesBarsOnSwipe = YES;

For more, https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/#//apple_ref/occ/instp/UINavigationController/hidesBarsOnSwipe

zipzapzoop
  • 138
  • 6