How can I scroll programmatically to the bottom in a UIWebView?

后端 未结 4 1643
感情败类
感情败类 2020-12-28 22:14

I know a similar question has been asked before but it seemed never been answered. I have a UIWebView and add some content by string. I use UIWebView because I add some imag

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-28 22:29

    SWIFT 4.x

    This is how you can scroll down Animated:

    func webViewDidFinishLoad(_ webView: UIWebView) {
        var scrollHeight: CGFloat = webView.scrollView.contentSize.height - webView.bounds.size.height
        if (0.0 > scrollHeight) {
            scrollHeight = 0.0
        }
        webView.scrollView.setContentOffset(CGPoint.init(x: 0.0, y: scrollHeight), animated: true)
    }
    

提交回复
热议问题