以编程方式滚动对 UIWebView 没有影响
Scroll programmatically has no effect on UIWebView
我有以下 UIWebView
实现,我想在加载 webview 后设置滚动。但是,以编程方式滚动对 UIWebView
.
没有影响
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSString *urlAddress = @"http://www.xxxx.com/private-dining";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[privateDiningWebView loadRequest:requestObj];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
privateDiningWebView.scrollView.contentOffset = CGPointMake(0, 300);
});
}
您可以为 UIWebview 设置委托并尝试此代码:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
privateDiningWebView.scrollView.contentOffset = CGPointMake(0, 300);
}
您需要在 webView
完成加载网页内容时调用它。
别忘了在你里面加上UIWebViewDelegate
ViewController
– webViewDidFinishLoad:(UIWebView *)webView
{
// UI Operation should be Done in Main Queue so you need to get
// main Queue to Access your webView
dispatch_async(dispatch_get_main_queue(), ^{
privateDiningWebView.scrollView.contentOffset = CGPointMake(0, 300);
});
}
我有以下 UIWebView
实现,我想在加载 webview 后设置滚动。但是,以编程方式滚动对 UIWebView
.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSString *urlAddress = @"http://www.xxxx.com/private-dining";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[privateDiningWebView loadRequest:requestObj];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
privateDiningWebView.scrollView.contentOffset = CGPointMake(0, 300);
});
}
您可以为 UIWebview 设置委托并尝试此代码:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
privateDiningWebView.scrollView.contentOffset = CGPointMake(0, 300);
}
您需要在 webView
完成加载网页内容时调用它。
别忘了在你里面加上UIWebViewDelegate
ViewController
– webViewDidFinishLoad:(UIWebView *)webView
{
// UI Operation should be Done in Main Queue so you need to get
// main Queue to Access your webView
dispatch_async(dispatch_get_main_queue(), ^{
privateDiningWebView.scrollView.contentOffset = CGPointMake(0, 300);
});
}