0

How can I make the navigation bar hide as the user scrolls? I'm trying to implement a browser like the Safari Mobile app.

note:

I'm using UIWebView and not a UIScrollView.

Moshe
  • 55,729
  • 73
  • 263
  • 420
  • Similar 2014, with some links and code ... http://stackoverflow.com/questions/19819165/imitate-ios-7-facebook-hide-show-expanding-contracting-navigation-bar – Fattie Feb 28 '14 at 20:44

3 Answers3

3

If you are using a UIScrollView then you can hide navigation bar in scroll view's delegate-

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [self.navigationController.navigationBar setHidden:TRUE];
}
saadnib
  • 11,097
  • 2
  • 31
  • 54
  • I'm using UIWebView and I want the view to scroll *with the users scroll*. – Moshe Apr 07 '11 at 04:40
  • The issue here is that scrolling will simpy hide the bar. In safari, the navbar scrolls as if it is part of the webview, until it is out of sight and I want that behavior, not the result of this code. – Moshe Apr 07 '11 at 05:41
  • I'm actually thinking of trying this with the contentOffset. It might work. – Moshe Aug 04 '11 at 00:33
0

Put the navigation bar inside the scroll view. In other words, make the scrollview your view controllers view.

Rog
  • 18,213
  • 5
  • 73
  • 93
  • Put the navbar in the webview? I'm skeptical of that for several reasons but it might work... – Moshe Apr 07 '11 at 12:04
  • Sorry I was under the impression you were using a scrollview. Might be worth a try with the webview tho, let us know if it works. – Rog Apr 07 '11 at 12:10
0

The standard approach used to be to add your view as a subview of the webview, and change the webview's contentInset property to shift everything in the webview downwards. I'm not sure if that still works with iOS 4.3.

Alternatively, if you search on SO, you'll find lots of questions the same as this one, with a variety of answers that may work, e.g.:

How to set content offset and content size in a UIWebView

iphone: View on top of UIWebView?

Community
  • 1
  • 1
Adam
  • 32,197
  • 16
  • 119
  • 146
  • Adding the bar works but setting the contentInset does not seem to do the trick. Is there something I'm missing? Perhaps `contentScaleMode` needs to be adjusted? – Moshe Apr 07 '11 at 17:48
  • Actually, looks like this question is a duplicate of several others now that you mention it. For now I'm going to dump this and try a different navigation scheme. Thanks! – Moshe Apr 07 '11 at 18:22