如何在uiwebview上设置滚动位置 [英] how to set scroll position on uiwebview
问题描述
我想在我加载的uiwebview上指定行。
我试过
I want to go to specify line on my uiwebview loaded. I tried
[webView stringByEvaluatingJavaScriptFromString:@window.scrollTo(0.0,
100.0);
[webView stringByEvaluatingJavaScriptFromString:@"window.scrollTo(0.0, 100.0)"];
但它不起作用。我的网页浏览仍然从页面顶部开始。
我只是想知道它,因为我在 UIView
中加载 UIWebview
。
在我的 UIView上查看我的代码
:
but its not working. My webview still start with top of the page.
I just wonder its because i load the UIWebview
inside UIView
.
Check my code below on my UIView
:
- (void)loadView {
webview = [[WebViewDetail alloc]initWithFrame:[UIScreen mainScreen].applicationFrame]; //initialize a mainView is a UIWebVIew
webview.managedObjectContext = self.managedObjectContext;
webview.kitab = self.kitab;
webview.currentPasal = self.pasal;
self.title = [NSString stringWithFormat:@"%@ %d", self.kitab, webview.currentPasal];
self.view=webview; //make the mainView as the view of this controller
}
我放了滚动条定位脚本在我的 UIWebView
:
and i put the scroll positioning script on my UIWebView
:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
int height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] intValue];
NSString* javascript = [NSString stringWithFormat:@"window.scrollBy(0, %d);", height];
[self stringByEvaluatingJavaScriptFromString:javascript];
}
在这种情况下我想把我的uiwebview放到页面底部加载视图时
但它完全不起作用,任何想法为什么?
我做错了吗?
in this case i want to put my uiwebview go to the bottom of the page when the view is loaded. But its totally not working, any idea why? Am i doing it wrong?
推荐答案
试试
webview.scrollView.contentOffset = CGPointMake(0, 100);
这篇关于如何在uiwebview上设置滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!