WkWebview contentOffset settign animated false时不工作
问题描述:
一旦内容加载完成,我需要设置WkWebView的contentOffset。我在webview didFinish导航里设置了webView.scrollView.setContentOffset(offset, animated: true)
。WkWebview contentOffset settign animated false时不工作
如果我设置动画为true
,它可以工作,但是当我将它设置为false
时,webView不会滚动。
如何在没有动画的情况下滚动webview?
答
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[webView.scrollView scrollRectToVisible:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f) animated:NO];
}
,或者您可以使用JavaScript
NSString *script = @"scrollTo(0, 0)";
[webView stringByEvaluatingJavaScriptFromString:script];
本文档可能解释为什么发生这种情况的原因:https://developer.apple.com/library/content/documentation/WindowsViews/Conceptual/UIScrollView_pg /ScrollingViewContent/ScrollingViewContent.html#//apple_ref/doc/uid/TP40008179-CH6-SW3当'animated:true'发送一系列事件,并且当其'animated:false'发送单个事件时。 – thedp