简体   繁体   中英

How to set Viewcontroller dynamic height according to webview at its bottom?

I have a view controller which has various components while a webview at its bottom everything is inside ScrollView but I ended up with double scroll one of main scrollview and one in the webview. How can I set the height of the main view to increase dynamically so that the webview would take its full height and I don't get a double scroll? I have tried something like this:

func webViewDidFinishLoad(webView: UIWebView) {

        myWebView.frame.size.height = 1
        myWebView.frame.size = webView.sizeThatFits(CGSizeZero)
    }

from this answer : here

As suggested in the answer below I did this

mainScroll.contentSize = CGSizeMake(mainScroll.contentSize.width, mainScroll.contentSize.height + webView.scrollView.contentSize.height);

that increased the height of scrollview according to content size of webview but the height of UIWebview remaided the same..

In Web view delegate method where it tells that loading has finished, you can do following

mainScroll.contentSize = CGSizeMake(mainScroll.contentSize.width, mainScroll.contentSize.height + webView.scrollView.contentSize.height);

I think this will work.

To increase the size of web view

webView.frame = CGRectMake(webView.frame.origin.x, webView.frame.origin.y, webView.frame.size.width, webView.scrollView.contentSize.height);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM