简体   繁体   English

如何使导航栏与网页一起滚动?

[英]How can I make the navigation bar scroll along with my webpage?

How can I make the navigation bar hide as the user scrolls? 当用户滚动时,如何隐藏导航栏? I'm trying to implement a browser like the Safari Mobile app. 我正在尝试实现类似Safari Mobile应用的浏览器。

note: 注意:

I'm using UIWebView and not a UIScrollView. 我正在使用UIWebView而不是 UIScrollView。

If you are using a UIScrollView then you can hide navigation bar in scroll view's delegate- 如果您使用的是UIScrollView,则可以在滚动视图的委托中隐藏导航栏,

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [self.navigationController.navigationBar setHidden:TRUE];
}

Put the navigation bar inside the scroll view. 将导航栏放入滚动视图中。 In other words, make the scrollview your view controllers view. 换句话说,将scrollview设置为视图控制器视图。

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. 以前的标准方法是将视图添加为Webview的子视图,并更改Webview的contentInset属性以将Webview中的所有内容向下移动。 I'm not sure if that still works with iOS 4.3. 我不确定这是否仍适用于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, eg: 另外,如果您搜索SO,则会发现很多与此问题相同的问题,并且可能会有各种答案,例如:

How to set content offset and content size in a UIWebView 如何在UIWebView中设置内容偏移量和内容大小

iphone: View on top of UIWebView? iPhone:在UIWebView之上查看?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM