How can I make the navigation bar scroll along wit

2019-09-08 09:25发布

问题:

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.

回答1:

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?



回答2:

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];
}


回答3:

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