// // CommonEditorWebCell.m // RedAnt Mobile // // Created by Jack on 2017/11/17. // Copyright © 2017年 Ray. All rights reserved. // #import "CommonEditorWebCell.h" //@interface CommonEditorWebCell() @interface CommonEditorWebCell() @end @implementation CommonEditorWebCell - (void)awakeFromNib { [super awakeFromNib]; // Initialization code [self setup]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (instancetype)initWithCoder:(NSCoder *)aDecoder { if (self = [super initWithCoder:aDecoder]) { [self setup]; } return self; } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self setup]; } return self; } - (void)dealloc { // [self removeObserver:self forKeyPath:@"self.webview.scrollView.frame"]; } - (void)setup { self.webview.scrollView.bounces=NO; self.webview.scrollView.directionalLockEnabled = true; self.webview.navigationDelegate = self; if (@available(iOS 11, *)) { self.webview.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } // [self addObserver:self forKeyPath:@"self.webview.scrollView.frame" options:NSKeyValueObservingOptionNew context:nil]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([keyPath isEqualToString:@"self.webview.scrollView.frame"]) { [self updateContentHeight]; } } #pragma mark - Web Delegate - (void)updateContentHeight { // return; [self.webview evaluateJavaScript:@"document.body.scrollHeight;" completionHandler:^(id _Nullable fitHeight, NSError * _Nullable error) { // NSString *h_str = [self.webview stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"]; NSString *h_str =fitHeight; float h = [h_str floatValue]; if (self.webDelegate) { [self.webDelegate commonEditorWebCell:self didChangeContentHeight:h]; } }]; } - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { [self updateContentHeight]; } //- (void)webViewDidFinishLoad:(UIWebView *)webView { // // [self updateContentHeight]; //} //- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { //// [self updateContentHeight]; //} @end