Cannot scroll in UIWebView in iOS

我与影子孤独终老i 提交于 2019-12-01 02:47:54
Krunal

To enable scrolling,

webview.scrollView.scrollEnabled = TRUE;

and instead of writing this,

webView.contentMode = UIViewContentModeScaleAspectFit;

write this,

webview.scalesPageToFit = TRUE;

Removing from Interface Builder and adding via code did for me. For some reason in IB it wasn't scrolling.

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 64, 320, 50)];
[self.view addSubview: webView];

These are the possible solutions.

i) You webview may be large in size than you expected or your content is lesser than the webview size.

2) Implement following method.

func webViewDidFinishLoad(webView: UIWebView)
{
    appDelegate.hideLoadingView()

    let res: NSString = webView.stringByEvaluatingJavaScriptFromString("document.body.offsetHeight;")!
    let h: CGFloat = CGFloat(res.integerValue)
    agreementContentView.scrollView.contentSize = CGSizeMake(webView.frame.size.width, h + 50); // Offset if required
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!