CommonEditorWebCell.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // CommonEditorWebCell.m
  3. // RedAnt Mobile
  4. //
  5. // Created by Jack on 2017/11/17.
  6. // Copyright © 2017年 Ray. All rights reserved.
  7. //
  8. #import "CommonEditorWebCell.h"
  9. @interface CommonEditorWebCell() <UIWebViewDelegate>
  10. @end
  11. @implementation CommonEditorWebCell
  12. - (void)awakeFromNib {
  13. [super awakeFromNib];
  14. // Initialization code
  15. [self setup];
  16. }
  17. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  18. [super setSelected:selected animated:animated];
  19. // Configure the view for the selected state
  20. }
  21. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
  22. if (self = [super initWithCoder:aDecoder]) {
  23. [self setup];
  24. }
  25. return self;
  26. }
  27. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  28. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  29. [self setup];
  30. }
  31. return self;
  32. }
  33. - (void)dealloc {
  34. // [self removeObserver:self forKeyPath:@"self.webview.scrollView.frame"];
  35. }
  36. - (void)setup {
  37. self.webview.scrollView.bounces=NO;
  38. self.webview.scrollView.directionalLockEnabled = true;
  39. // [self addObserver:self forKeyPath:@"self.webview.scrollView.frame" options:NSKeyValueObservingOptionNew context:nil];
  40. }
  41. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
  42. if ([keyPath isEqualToString:@"self.webview.scrollView.frame"]) {
  43. [self updateContentHeight];
  44. }
  45. }
  46. #pragma mark - Web Delegate
  47. - (void)updateContentHeight {
  48. // return;
  49. NSString *h_str = [self.webview stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];
  50. float h = [h_str floatValue];
  51. if (self.webDelegate) {
  52. [self.webDelegate commonEditorWebCell:self didChangeContentHeight:h];
  53. }
  54. }
  55. - (void)webViewDidFinishLoad:(UIWebView *)webView {
  56. [self updateContentHeight];
  57. }
  58. - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
  59. // [self updateContentHeight];
  60. }
  61. @end