I am building an application that includes a UIWebView
containing a large number of images, CSS, embedded video, and JavaScript tap handlers. Scrolling performance
I had a similar issue a while ago. I found that putting the webview inside of a scrollview improved scroll performance dramatically. After the webview finished loading I disabled scrolling on the webview, set the webview's frame and the scrollview's contentSize to be the size of the webview's content.
-(void) webViewDidFinishLoad:(UIWebView *)webView {
float size = [[self.webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
[self.scrollView setContentSize:CGSizeMake(self.view.frame.size.width, size)];
[webView setFrame:CGRectMake(webView.frame.origin.x,
webView.frame.origin.y,
webView.frame.size.width,
size)];
[(UIScrollView*)[webView.subviews objectAtIndex:0] setScrollEnabled:NO];
}
I'm assuming that the webview doesn't load an image until it is about to appear on screen, which caused the stuttering, and by putting it in a scrollview and setting the frame to the content size it must load them ahead of time, but I'm not certain. I'm also sure this has consequences (ie, increased memory usage up front), but I never had any problems doing it this way.