Skip to content

Instantly share code, notes, and snippets.

@boboboa32
Last active June 30, 2016 05:51
Show Gist options
  • Save boboboa32/0d901d8b3ae9296ab39af4ea2a8b7d1f to your computer and use it in GitHub Desktop.
Save boboboa32/0d901d8b3ae9296ab39af4ea2a8b7d1f to your computer and use it in GitHub Desktop.
caculate WKWebView content height
- (void)viewDidLoad {
...
[self.webView.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];
}
- (void)dealloc
{
[self.webView.scrollView removeObserver:self forKeyPath:@"contentSize" context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
if (object == self.webView.scrollView && [keyPath isEqual:@"contentSize"]) {
// we are here because the contentSize of the WebView's scrollview changed.
UIScrollView *scrollView = self.webView.scrollView;
NSLog(@"New contentSize: %f x %f", scrollView.contentSize.width, scrollView.contentSize.height);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment