0

I have disqusView(link) in UIWebView, I want to scroll webView as the size of disqusView, I don't want default scroll of webView

here is my code, in these I'm getting more height then actual height of webView content size.

func webViewDidFinishLoad(webView: UIWebView) {

 let cgfloat = web_discus.scrollView.contentSize.height as CGFloat
}

or

web_discus.stringByEvaluatingJavaScriptFromString("document.hight")! as String

but both give more height then actual that`s why it show more blank space while scrolling down..

I also tried this one :

web_discus.stringByEvaluatingJavaScriptFromString("document.body.offsetHeight")! as String

Is there any way to get perfect hight for webView content ?

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
MiTal Khandhar
  • 275
  • 1
  • 4
  • 15

2 Answers2

1

Seems you want the contentSize of the webView? If that is the case, then this other StackOverflow question should point you in the right direction link

Essentially you'd do webView.sizeThatFits(CGSizeZero).

Community
  • 1
  • 1
BHendricks
  • 4,423
  • 6
  • 32
  • 59
0

If I'm not mistaking, I think you should use window.pageYOffset:

if let myPostion = web_discus.stringByEvaluatingJavaScript(from: "window.pageYOffset"), let myPostionCGFloat = NumberFormatter().number(from: myPostion) {
        web_discus.scrollView.contentSize.height = CGFloat(myPostionCGFloat)
    }
}
Ahmad F
  • 30,560
  • 17
  • 97
  • 143