It's seems that webView
is changing its scrollView
contentSize
after page loading.
In your init set self as a delegate of WebView
:
[webView setDelegate: self];
And add this method:
- (void)webViewDidFinishLoad: (UIWebView *)webView {
[webView.scrollView setContentSize: CGSizeMake(768.0, 2000.0)];
}
In my test case it's working fine.
UPDATED:
Calling javascript methods sometimes does not trigger webViewDidFinishLoad
. So the most universal technique will be Key-Value Observing.
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: %f x %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)];
}
}
Do not forget to remove observer in case of dealloc:
[webView.scrollView removeObserver:self forKeyPath:@"contentSize"];