| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- //
- // CommonEditorWebCell.m
- // RedAnt Mobile
- //
- // Created by Jack on 2017/11/17.
- // Copyright © 2017年 Ray. All rights reserved.
- //
- #import "CommonEditorWebCell.h"
- @interface CommonEditorWebCell() <UIWebViewDelegate>
- @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 addObserver:self forKeyPath:@"self.webview.scrollView.frame" options:NSKeyValueObservingOptionNew context:nil];
- }
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
- if ([keyPath isEqualToString:@"self.webview.scrollView.frame"]) {
- [self updateContentHeight];
- }
- }
- #pragma mark - Web Delegate
- - (void)updateContentHeight {
-
- NSString *h_str = [self.webview stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];
- float h = [h_str floatValue];
-
- if (self.webDelegate) {
- [self.webDelegate commonEditorWebCell:self didChangeContentHeight:h];
- }
- }
- - (void)webViewDidFinishLoad:(UIWebView *)webView {
-
- [self updateContentHeight];
- }
- - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
- [self updateContentHeight];
- }
- @end
|