在IOS中,如何知道UIWebView的滚动条是否在顶部?

发布于 2024-12-27 15:21:48 字数 512 浏览 6 评论 0原文

我正在制作一个 iOS 应用程序,它有这样的操作。

http://www.flickr.com/photos/71607441@N07/6721920809/ 是全屏网页视图。当滚动条位于顶部时,如果我触摸网络视图,它就会下降并覆盖一半屏幕。 (如果滚动条不在顶部,则该操作不会执行)

http:// /www.flickr.com/photos/71607441@N07/6721847313/ 像这样。

我很困惑如何知道滚动条的位置在哪里。

UIWebView 的属性很少,我想我需要将 UIWebView 嵌入 UIScrollView 中,或者我是否必须使用 javascript?

I am making an iOS application which has an action like this.

http://www.flickr.com/photos/71607441@N07/6721920809/ is a full screen web view. when the scroller is on top, If I touch the webview, It goes down and cover half of the screen. (If the scroller is not on the top, the action won't do)

http://www.flickr.com/photos/71607441@N07/6721847313/ like this.

I am confused how to know where the scroller position is.

UIWebView has few properties, and I guess I need to embed the UIWebView in a UIScrollView, or Do I have to use javascript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

八巷 2025-01-03 15:21:48

不确定你到底想做什么,但如果你想将 UIWebView 作为一个整体向下移动,我会将其添加到 UIView 中,然后将 UIView 放入 UIScrollView 中。这将使其相对于添加到 UIView 的任何其他元素保持固定位置。尽管 UIWebView 已经包含 UIScrollView 并且必须在两者之间正确处理触摸事件,但您可能会遇到一些奇怪的行为。

如果你想知道网页视图在“内部”向下滚动了多远,你可以使用这个小技巧:

NSString *scrollTopStr = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollTop;"];    
NSLog(@"scroll top: %@", scrollTopStr);

Not sure what you're trying to do exactly, but if you're trying to move the UIWebView down as a whole I'd add it to a UIView and then put the UIView into a UIScrollView. That will keep it in a fixed position relative to any other elements you add to the UIView. You may wind up with some odd behaviors though as UIWebView already contains a UIScrollView and the touch events will have to be handled between the two correctly.

If you're trying to find out how far the web view is scrolled down "inside" itself, you can use this little hack:

NSString *scrollTopStr = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollTop;"];    
NSLog(@"scroll top: %@", scrollTopStr);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文