GoodsExplainCell.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. //
  2. // GoodsExplainCell.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2020/3/28.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "GoodsExplainCell.h"
  9. #import "XHWebImageAutoSize.h"
  10. @implementation GoodsExplainCell
  11. - (void)awakeFromNib {
  12. [super awakeFromNib];
  13. // Initialization code
  14. }
  15. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  16. [super setSelected:selected animated:animated];
  17. // Configure the view for the selected state
  18. }
  19. #pragma mark -- 商品简介webview
  20. - (WKWebView *)webView{
  21. if (!_webView) {
  22. _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, _window_width, _window_height-64-statusbarHeight-40-80)];
  23. _webView.navigationDelegate = self;
  24. _webView.opaque = NO;
  25. _webView.multipleTouchEnabled = YES;
  26. _webView.scrollView.delegate = self;
  27. _webView.scrollView.bounces = NO;
  28. _webView.scrollView.showsVerticalScrollIndicator = NO;
  29. _webView.scrollView.scrollEnabled = YES;
  30. _webView.scrollView.panGestureRecognizer.enabled = NO;
  31. }
  32. return _webView;
  33. }
  34. -(UIScrollView *)backScroll
  35. {
  36. if (!_backScroll) {
  37. _backScroll = [[UIScrollView alloc]init];
  38. _backScroll.frame = CGRectMake(0, 0, _window_width, _window_height-64-statusbarHeight-40-80);
  39. _backScroll.backgroundColor = UIColor.whiteColor;
  40. }
  41. return _backScroll;
  42. }
  43. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  44. {
  45. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  46. if (self) {
  47. allHeight = 0;
  48. _imageArray = [NSMutableArray array];
  49. // NSString * htmlStyle = @" <style type=\"text/css\"> *{min-width: 80% !important;max-width: 100% !important;} table{ width: 100% !important;} img{ height: auto !important;} </style> ";
  50. // NSString *aaa = @"<meta content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0\" name=\"viewport\">";
  51. // htmlString = [aaa stringByAppendingString:htmlStyle];
  52. // [self.contentView addSubview:self.webView];
  53. [self.contentView addSubview:self.backScroll];
  54. }
  55. return self;
  56. }
  57. -(void)setModel:(CommodityDetailModel *)model
  58. {
  59. _model = model;
  60. //计算评价content
  61. // CGFloat content_height = [publi heightOfString:model.content andFont:[UIFont systemFontOfSize:14] andWidth:_window_width-32];
  62. CGFloat content_height = [PublicObj heightOfString:model.content andFont:[UIFont systemFontOfSize:14] andWidth:_window_width-32];
  63. content = [[UILabel alloc]init];
  64. content.frame = CGRectMake(16, 0, _window_width-32, content_height);
  65. content.text = model.content;
  66. content.font = [UIFont systemFontOfSize:14];
  67. content.textColor = UIColor.blackColor;
  68. content.numberOfLines = 0;
  69. [self.backScroll addSubview:content];
  70. _topMas = content.mas_bottom;
  71. _spacess = content_height+15;
  72. imageFloat =_spacess;
  73. NSArray *array = model.pictures_format;
  74. for (int i = 0; i < array.count; i ++) {
  75. CGFloat imageHeight = [XHWebImageAutoSize imageHeightForURL:[NSURL URLWithString:array[i]] layoutWidth:_window_width estimateHeight:256];
  76. UIImageView *thumbImg = [[UIImageView alloc]init];
  77. [thumbImg sd_setImageWithURL:[NSURL URLWithString:array[i]]completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  78. thumbImg.frame = CGRectMake(0,imageFloat, _window_width, imageHeight);
  79. imageFloat =imageFloat+imageHeight;
  80. }];
  81. [self.backScroll addSubview:thumbImg];
  82. }
  83. self.backScroll.contentSize = CGSizeMake(_window_width, imageFloat+20);
  84. // NSString * htmlStyle22 = @" <style type=\"text/css\">body{font-size:30} </style> ";
  85. //
  86. // NSString *contentStr = [model.content stringByReplacingOccurrencesOfString:@"\n" withString:@"<br>"];
  87. //
  88. // NSString *htmlStr = [NSString stringWithFormat:@"%@<p>%@</p>",htmlStyle22,contentStr];//model.content
  89. //
  90. // for (NSString *str in array) {
  91. // NSString *ssss = [NSString stringWithFormat:@"<img src='%@'></img>",str];
  92. // htmlStr = [NSString stringWithFormat:@"%@%@",htmlStr,ssss];
  93. // }
  94. // NSString * htmlStyle = @" <style type=\"text/css\"> *{min-width: 100% !important;max-width: 100% !important;} img{ height: auto !important;} </style> ";
  95. // htmlStr = [htmlStyle stringByAppendingString:htmlStr];
  96. // [_webView loadHTMLString:htmlStr baseURL:nil];
  97. // NSURL *url = [NSURL URLWithString:@"https://livenew.yunbaozb.com/appapi/feedback/test"];
  98. // NSURLRequest *request = [NSURLRequest requestWithURL:url];
  99. // [_webView loadRequest:request];
  100. }
  101. - (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
  102. [webView evaluateJavaScript:@"document.body.scrollHeight" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
  103. // _webView.frame = CGRectMake(0, 0, _window_width, [result doubleValue]);//将WKWebView的高度设置为内容高度
  104. // //刷新制定位置Cell
  105. // _backScrollView.contentSize = CGSizeMake(0, _webView.bottom);
  106. }];
  107. }
  108. - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
  109. NSURLRequest *request = navigationAction.request;
  110. if ([request.URL.scheme isEqualToString: @"image-preview"])
  111. {
  112. //启动图片浏览器, 跳转到图片浏览页面
  113. if (_imageArray.count != 0) {
  114. // HZPhotoBrowser *browserVc = [[HZPhotoBrowser alloc] init];
  115. // browserVc.imageArray = imageArray;
  116. // browserVc.imageCount = imageArray.count; // 图片总数
  117. // browserVc.currentImageIndex = (int)[imageArray indexOfObject:url];//当前点击的图片
  118. // [browserVc show];
  119. }
  120. decisionHandler(WKNavigationActionPolicyAllow);
  121. return;
  122. }
  123. decisionHandler(WKNavigationActionPolicyAllow);
  124. NSLog(@"在发送请求之前:%@",navigationAction.request.URL.absoluteString);
  125. }
  126. //- (void)awakeFromNib {
  127. // [super awakeFromNib];
  128. // // Initialization code
  129. //}
  130. //
  131. //- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  132. // [super setSelected:selected animated:animated];
  133. //
  134. // // Configure the view for the selected state
  135. //}
  136. //#pragma mark -- 商品简介webview
  137. //- (WKWebView *)webView{
  138. // if (!_webView) {
  139. // _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, _window_width, _window_height-64-statusbarHeight-40-80)];
  140. // _webView.navigationDelegate = self;
  141. // _webView.opaque = NO;
  142. // _webView.multipleTouchEnabled = YES;
  143. // _webView.scrollView.delegate = self;
  144. // _webView.scrollView.bounces = NO;
  145. // _webView.scrollView.showsVerticalScrollIndicator = NO;
  146. // _webView.scrollView.scrollEnabled = YES;
  147. // _webView.scrollView.panGestureRecognizer.enabled = NO;
  148. // }
  149. // return _webView;
  150. //}
  151. //-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  152. //{
  153. // self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  154. // if (self) {
  155. // allHeight = 0;
  156. // _imageArray = [NSMutableArray array];
  157. // NSString * htmlStyle = @" <style type=\"text/css\"> *{min-width: 80% !important;max-width: 100% !important;} table{ width: 100% !important;} img{ height: auto !important;} </style> ";
  158. // NSString *aaa = @"<meta content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0\" name=\"viewport\">";
  159. // htmlString = [aaa stringByAppendingString:htmlStyle];
  160. // [self.contentView addSubview:self.webView];
  161. //
  162. // }
  163. // return self;
  164. //}
  165. //-(void)setModel:(CommodityDetailModel *)model
  166. //{
  167. // _model = model;
  168. // //计算评价content
  169. // CGFloat content_height = [PublicObj heightOfString:model.content andFont:[UIFont systemFontOfSize:14] andWidth:_window_width-32];
  170. //
  171. // content.frame = CGRectMake(16, 0, _window_width-32, content_height);
  172. // content.text = model.content;
  173. //
  174. // _topMas = content.mas_bottom;
  175. // _spacess = content_height+15;
  176. //
  177. // NSArray *array = model.pictures_format;
  178. // NSString * htmlStyle22 = @" <style type=\"text/css\">body{font-size:30} </style> ";
  179. //
  180. // NSString *htmlStr = [NSString stringWithFormat:@"%@<p>%@</p>",htmlStyle22,model.content];
  181. //
  182. // for (NSString *str in array) {
  183. // NSString *ssss = [NSString stringWithFormat:@"<img src='%@'></img>",str];
  184. // htmlStr = [NSString stringWithFormat:@"%@%@",htmlStr,ssss];
  185. // }
  186. // NSString * htmlStyle = @" <style type=\"text/css\"> *{min-width: 100% !important;max-width: 100% !important;} img{ height: auto !important;} </style> ";
  187. // htmlStr = [htmlStyle stringByAppendingString:htmlStr];
  188. // [_webView loadHTMLString:htmlStr baseURL:nil];
  189. //}
  190. //- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
  191. // [webView evaluateJavaScript:@"document.body.scrollHeight" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
  192. //// _webView.frame = CGRectMake(0, 0, _window_width, [result doubleValue]);//将WKWebView的高度设置为内容高度
  193. //// //刷新制定位置Cell
  194. //// _backScrollView.contentSize = CGSizeMake(0, _webView.bottom);
  195. // }];
  196. //}
  197. //- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
  198. //
  199. // NSURLRequest *request = navigationAction.request;
  200. // if ([request.URL.scheme isEqualToString: @"image-preview"])
  201. // {
  202. //
  203. // NSString *url = [request.URL.absoluteString substringFromIndex:14];
  204. // //启动图片浏览器, 跳转到图片浏览页面
  205. // if (_imageArray.count != 0) {
  206. //
  207. //// HZPhotoBrowser *browserVc = [[HZPhotoBrowser alloc] init];
  208. //// browserVc.imageArray = imageArray;
  209. //// browserVc.imageCount = imageArray.count; // 图片总数
  210. //// browserVc.currentImageIndex = (int)[imageArray indexOfObject:url];//当前点击的图片
  211. //// [browserVc show];
  212. //
  213. // }
  214. // decisionHandler(WKNavigationActionPolicyAllow);
  215. // return;
  216. //
  217. // }
  218. //
  219. // decisionHandler(WKNavigationActionPolicyAllow);
  220. // NSLog(@"在发送请求之前:%@",navigationAction.request.URL.absoluteString);
  221. //}
  222. @end