Context
ViewController
UIWebView
objects as subviews of a UIScrollView
are in this ViewControllers
view- (void)webViewDidFinishLoad:(UIWebView *)webView
gets called twice as expected for both UIWebViews
UIWebViews
using sizeThatFits
once their content has loaded (in the webViewDidFinishLoad
methodWhat I want to do
Once both WebViews have loaded their content I want to set the height of the UIScrollView
that they are in relative to the WebViews height. Basically I want the UIScrollView
to be tall enough to scroll all the way through the text in the UIWebViews
.
Possible Solutions I've thought of
webViewDidFinishLoad
method, and when it is equal to the amount of WebViews on the view call a method that sets the height of the UIScrollView
. UIScrollView
in webViewDidFinishLoad
- it will be called multiple times, but the last call will be the correct height. Question
How do I work out when both webViews have loaded in a "better" way than the possible solutions above?
I think you're making this too complicated. As you suggest at the end of your question, why not just set the height (contentSize.height, I believe is what you want) with each webViewDidFinishLoad:? You can test to see which webview is the tallest and set the height to that value:
CGSize size = CGSizeMake(320, 0);
size.height = webView1.frame.size.height + webView2.frame.size.height;
scrollView.contentSize = size;
IMO it's not a great idea to be placing multiple webviews inside a scrollview (although I've done it before too...) Could you consider getting rid of the scroll view altogether and having a single webview (which is self-scrolling) and has two iframe elements, which each display your original webview1/webview2 content?