The webView change its scrollView contentSize after the page loads.
In your init, set self as a webView delegate:
[webView setDelegate: self]
And add this method:
- (void)webViewDidFinishLoad: (UIWebView *)webView { [webView.scrollView setContentSize: CGSizeMake(768.0, 2000.0)]; }
In my test case, it works fine.
UPDATED:
Calling javascript methods sometimes does not start webViewDidFinishLoad . Thus, monitoring the key values ββwill be the most universal method.
In init:
[webView.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];
And somewhere this method:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { UIScrollView * scrlView = (UIScrollView *) object; if ([keyPath isEqual:@"contentSize"]) { NSLog(@"New contentSize: %fx %f",scrlView.contentSize.width,scrlView.contentSize.height); if(scrlView.contentSize.width!=768.0||scrlView.contentSize.height!=2000.0) [scrlView setContentSize:CGSizeMake(768.0, 2000.0)]; } }
Remember to remove the observer in the case of dealloc:
[webView.scrollView removeObserver:self forKeyPath:@"contentSize"];
source share