Skip to content

Instantly share code, notes, and snippets.

@matt-curtis
Last active December 18, 2015 20:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matt-curtis/5843862 to your computer and use it in GitHub Desktop.
Save matt-curtis/5843862 to your computer and use it in GitHub Desktop.
Redraw/relayout UIWebView's Webkit DOM
- (void) forceRedrawInWebView:(UIWebView*)webView {
NSArray *views = webView.scrollView.subviews;
for(int i = 0; i<views.count; i++){
UIView *view = views[i];
//if([NSStringFromClass([view class]) isEqualToString:@"UIWebBrowserView"]){
[view setNeedsDisplayInRect:webView.bounds]; // Webkit Repaint, usually fast
[view setNeedsLayout]; // Webkit Relayout (slower than repaint)
// Causes redraw & relayout of *entire* UIWebView, onscreen and off, usually intensive
[view setNeedsDisplay];
[view setNeedsLayout];
// break; // glass in case of if statement (thanks Jake)
//}
}
}
// Javascript counterpart - will in some cases suffice and do the same thing.
window.scrollBy(1, 1);
window.scrollBy(-1, -1);
@matt-curtis
Copy link
Author

Stack Overflow Question/Answer http://stackoverflow.com/a/17257650/183471

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment