Last active
June 30, 2016 05:51
-
-
Save boboboa32/0d901d8b3ae9296ab39af4ea2a8b7d1f to your computer and use it in GitHub Desktop.
caculate WKWebView content height
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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