Commit 8507240e9e03f61cb4115401409570657357db9f

Authored by yanglingyu
1 parent eb977ebe

变灰代码添加,答记者问简介显示bug修复

CNLiveScioLive.xcodeproj/project.pbxproj
... ... @@ -11,6 +11,8 @@
11 11 080AB4C6217AD4F4008BA78F /* TemplateShareManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 080AB4C5217AD4F4008BA78F /* TemplateShareManager.m */; };
12 12 080AB4C7217AD4F4008BA78F /* TemplateShareManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 080AB4C5217AD4F4008BA78F /* TemplateShareManager.m */; };
13 13 080AB4C8217AD4F4008BA78F /* TemplateShareManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 080AB4C5217AD4F4008BA78F /* TemplateShareManager.m */; };
  14 + 0816B5E42648C23A005E1F8C /* UIColor+CNGray.m in Sources */ = {isa = PBXBuildFile; fileRef = 0816B5E32648C23A005E1F8C /* UIColor+CNGray.m */; };
  15 + 0816B5E92648C320005E1F8C /* WKWebView+CNGray.m in Sources */ = {isa = PBXBuildFile; fileRef = 0816B5E82648C320005E1F8C /* WKWebView+CNGray.m */; };
14 16 083847E1215C5DDD00186618 /* VPImageCropperViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 083847E0215C5DDD00186618 /* VPImageCropperViewController.m */; };
15 17 083847E2215C5DDD00186618 /* VPImageCropperViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 083847E0215C5DDD00186618 /* VPImageCropperViewController.m */; };
16 18 083847E3215C5DDD00186618 /* VPImageCropperViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 083847E0215C5DDD00186618 /* VPImageCropperViewController.m */; };
... ... @@ -647,6 +649,8 @@
647 649 08C090BF215116CB00E23D16 /* CNLiveIndicatorTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C090BE215116CB00E23D16 /* CNLiveIndicatorTableViewCell.m */; };
648 650 08C090C0215116CB00E23D16 /* CNLiveIndicatorTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C090BE215116CB00E23D16 /* CNLiveIndicatorTableViewCell.m */; };
649 651 08C090C1215116CB00E23D16 /* CNLiveIndicatorTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C090BE215116CB00E23D16 /* CNLiveIndicatorTableViewCell.m */; };
  652 + 08C28A30263932960065B372 /* UIImageView+CNGrayImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C28A2D263932960065B372 /* UIImageView+CNGrayImage.m */; };
  653 + 08C28A31263932960065B372 /* UIImage+CNGray.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C28A2F263932960065B372 /* UIImage+CNGray.m */; };
650 654 08C721B924CAC9B700970100 /* SDCycleScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C721AD24CAC9B700970100 /* SDCycleScrollView.m */; };
651 655 08C721BA24CAC9B700970100 /* UIView+SDExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C721AE24CAC9B700970100 /* UIView+SDExtension.m */; };
652 656 08C721BB24CAC9B700970100 /* SDCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C721AF24CAC9B700970100 /* SDCollectionViewCell.m */; };
... ... @@ -732,6 +736,10 @@
732 736 0802446C2624267800BD68E8 /* SdkMgr.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SdkMgr.m; sourceTree = "<group>"; };
733 737 080AB4C4217AD4F4008BA78F /* TemplateShareManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TemplateShareManager.h; sourceTree = "<group>"; };
734 738 080AB4C5217AD4F4008BA78F /* TemplateShareManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TemplateShareManager.m; sourceTree = "<group>"; };
  739 + 0816B5E22648C23A005E1F8C /* UIColor+CNGray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIColor+CNGray.h"; sourceTree = "<group>"; };
  740 + 0816B5E32648C23A005E1F8C /* UIColor+CNGray.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIColor+CNGray.m"; sourceTree = "<group>"; };
  741 + 0816B5E72648C320005E1F8C /* WKWebView+CNGray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WKWebView+CNGray.h"; sourceTree = "<group>"; };
  742 + 0816B5E82648C320005E1F8C /* WKWebView+CNGray.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "WKWebView+CNGray.m"; sourceTree = "<group>"; };
735 743 083847DF215C5DDD00186618 /* VPImageCropperViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VPImageCropperViewController.h; sourceTree = "<group>"; };
736 744 083847E0215C5DDD00186618 /* VPImageCropperViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VPImageCropperViewController.m; sourceTree = "<group>"; };
737 745 0838483C215C838B00186618 /* CNLiveENTabBarController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CNLiveENTabBarController.h; sourceTree = "<group>"; };
... ... @@ -1111,6 +1119,10 @@
1111 1119 08C090B421510E4B00E23D16 /* CNLiveTableViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CNLiveTableViewCell.m; sourceTree = "<group>"; };
1112 1120 08C090BD215116CB00E23D16 /* CNLiveIndicatorTableViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CNLiveIndicatorTableViewCell.h; sourceTree = "<group>"; };
1113 1121 08C090BE215116CB00E23D16 /* CNLiveIndicatorTableViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CNLiveIndicatorTableViewCell.m; sourceTree = "<group>"; };
  1122 + 08C28A2C263932960065B372 /* UIImage+CNGray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+CNGray.h"; sourceTree = "<group>"; };
  1123 + 08C28A2D263932960065B372 /* UIImageView+CNGrayImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+CNGrayImage.m"; sourceTree = "<group>"; };
  1124 + 08C28A2E263932960065B372 /* UIImageView+CNGrayImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImageView+CNGrayImage.h"; sourceTree = "<group>"; };
  1125 + 08C28A2F263932960065B372 /* UIImage+CNGray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+CNGray.m"; sourceTree = "<group>"; };
1114 1126 08C721AA24CAC9B700970100 /* UIView+SDExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+SDExtension.h"; sourceTree = "<group>"; };
1115 1127 08C721AB24CAC9B700970100 /* SDCycleScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCycleScrollView.h; sourceTree = "<group>"; };
1116 1128 08C721AC24CAC9B700970100 /* SDCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCollectionViewCell.h; sourceTree = "<group>"; };
... ... @@ -1822,6 +1834,7 @@
1822 1834 08C08FCF214FA01B00E23D16 /* Tools */ = {
1823 1835 isa = PBXGroup;
1824 1836 children = (
  1837 + 08C28A2B263932650065B372 /* ImageGray */,
1825 1838 0802446A262425DB00BD68E8 /* DeviceUUID */,
1826 1839 08C721A924CAC9B700970100 /* SDCycleScrollView */,
1827 1840 080AB4BE217AD457008BA78F /* ShareTool */,
... ... @@ -2228,6 +2241,21 @@
2228 2241 path = XWHTTPTool;
2229 2242 sourceTree = "<group>";
2230 2243 };
  2244 + 08C28A2B263932650065B372 /* ImageGray */ = {
  2245 + isa = PBXGroup;
  2246 + children = (
  2247 + 08C28A2C263932960065B372 /* UIImage+CNGray.h */,
  2248 + 08C28A2F263932960065B372 /* UIImage+CNGray.m */,
  2249 + 08C28A2E263932960065B372 /* UIImageView+CNGrayImage.h */,
  2250 + 08C28A2D263932960065B372 /* UIImageView+CNGrayImage.m */,
  2251 + 0816B5E22648C23A005E1F8C /* UIColor+CNGray.h */,
  2252 + 0816B5E32648C23A005E1F8C /* UIColor+CNGray.m */,
  2253 + 0816B5E72648C320005E1F8C /* WKWebView+CNGray.h */,
  2254 + 0816B5E82648C320005E1F8C /* WKWebView+CNGray.m */,
  2255 + );
  2256 + path = ImageGray;
  2257 + sourceTree = "<group>";
  2258 + };
2231 2259 08C721A924CAC9B700970100 /* SDCycleScrollView */ = {
2232 2260 isa = PBXGroup;
2233 2261 children = (
... ... @@ -2814,6 +2842,7 @@
2814 2842 files = (
2815 2843 08B5C5822153400700F5476E /* CNNewsoundBaseModel.m in Sources */,
2816 2844 08585DB5215B4DA300FC2CA2 /* CNLiveAdvancedSearchViewController.m in Sources */,
  2845 + 08C28A30263932960065B372 /* UIImageView+CNGrayImage.m in Sources */,
2817 2846 08C08FE0214FA01B00E23D16 /* CNNewsoundViewController.m in Sources */,
2818 2847 08585DB2215B4DA300FC2CA2 /* SearchResultViewController.m in Sources */,
2819 2848 08585D47215B4C7200FC2CA2 /* UIColor+PGHex.m in Sources */,
... ... @@ -2822,6 +2851,7 @@
2822 2851 08384847215C98A000186618 /* CNHomeENViewController.m in Sources */,
2823 2852 08C090BF215116CB00E23D16 /* CNLiveIndicatorTableViewCell.m in Sources */,
2824 2853 085D85F22159C0790037D480 /* Reachability.m in Sources */,
  2854 + 0816B5E92648C320005E1F8C /* WKWebView+CNGray.m in Sources */,
2825 2855 08940D832154F15900F85DB6 /* VideoDetailViewController.m in Sources */,
2826 2856 085D862F2159C72F0037D480 /* ZXVideoPlayerTimeIndicatorView.m in Sources */,
2827 2857 084ACE2C2154C6AA0089E035 /* CNLiveNewsThreePicTableViewCell.m in Sources */,
... ... @@ -2849,6 +2879,7 @@
2849 2879 08471A9F25E7864E0043FC2D /* VideoDetailPresent.m in Sources */,
2850 2880 C3E502DA2152432700DA4320 /* CNHomeRightTableViewCell.m in Sources */,
2851 2881 08C090AB215103C400E23D16 /* CNLiveHeaderView.m in Sources */,
  2882 + 08C28A31263932960065B372 /* UIImage+CNGray.m in Sources */,
2852 2883 08585D56215B4C7200FC2CA2 /* PGDatePicker+Time.m in Sources */,
2853 2884 08C08FE6214FA01B00E23D16 /* CNLiveTabBarController.m in Sources */,
2854 2885 08585D53215B4C7200FC2CA2 /* NSCalendar+PGCurrent.m in Sources */,
... ... @@ -2971,6 +3002,7 @@
2971 3002 0838487D215CF6FC00186618 /* BaseViewController.m in Sources */,
2972 3003 C3004D35215A583400A83C3D /* CNLiveNewsDetailsView.m in Sources */,
2973 3004 08C721BA24CAC9B700970100 /* UIView+SDExtension.m in Sources */,
  3005 + 0816B5E42648C23A005E1F8C /* UIColor+CNGray.m in Sources */,
2974 3006 );
2975 3007 runOnlyForDeploymentPostprocessing = 0;
2976 3008 };
... ...
CNLiveScioLive/Pages/Header/PrefixHeader.pch
... ... @@ -80,7 +80,9 @@
80 80  
81 81 #import "Reachability.h"
82 82 #import "JSONKit.h"
83   -
  83 +#import "UIImageView+CNGrayImage.h"
  84 +#import "UIColor+CNGray.h"
  85 +#import "WKWebView+CNGray.h"
84 86 //友盟统计
85 87 #import <UMCommon/MobClick.h>
86 88 #import <UMCommon/UMConfigure.h>
... ...
CNLiveScioLive/Pages/Home/CNHomeViewController.m
... ... @@ -63,21 +63,6 @@
63 63 }
64 64  
65 65 }
66   -// NSDictionary *fullcol = dic[@"fullcol"];
67   -// NSArray *dataArray = fullcol[@"programs"];
68   -// if ([dataArray isKindOfClass:[NSArray class]]) {
69   -// for (NSDictionary *dics in dataArray) {
70   -// [CNHomeModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
71   -// return @{ @"ID" : @"id" ,@"Description" : @"description" };
72   -// }];
73   -//
74   -// NSLog(@"%@",dics);
75   -// [self.data addObject:[CNHomeModel mj_objectWithKeyValues:dics]];
76   -//
77   -// }
78   -//
79   -// }
80   -// NSArray *allArray = [NSArray arrayWithContentsOfFile:ALLARRAYLIST_PATH];
81 66  
82 67 NSMutableArray *controllers = [NSMutableArray array];
83 68 NSMutableArray *titles = [NSMutableArray array];
... ...
CNLiveScioLive/Pages/Home/新闻详情/OldController/OldVideoDetailViewController.m
... ... @@ -67,11 +67,13 @@
67 67 NSString* htmldate = @"";
68 68 NSString* htmlForm = @"";
69 69 NSString* content = @"";
  70 + NSString* line = @"";
70 71 if ([_dictionary objectForKey:@"publishDate"] && [_dictionary objectForKey:@"author"]) {
71 72 htmldate = [[NSString alloc] initWithFormat:@"<html><p>%@</p><body>",[NSString stringWithFormat:@"%@",[_dictionary objectForKey:@"publishDate"]]];
72 73 htmlForm = [[NSString alloc] initWithFormat:@"<html><p>%@:%@</p><body>", CustomStr(@"Source"), _dictionary[@"author"]];
73 74 self.authorName = _dictionary[@"author"];
74 75 if (self.content&&![self.content isEqualToString:@""]) {
  76 + line = [[NSString alloc] initWithFormat:@"<hr width=\"device-width\" size=\"0.5\" color=\"gray\" align=\"left\" noshade=\"noshade\">"];
75 77 content = [[NSString alloc] initWithFormat:@"<div class=\"logo\" style=\"text-indent:2em\"><font style=\"font-size:%@px;\">%@</font></div>",fontArray[fontIndex],self.content];
76 78 }
77 79 } else {
... ... @@ -83,7 +85,7 @@
83 85  
84 86 NSString* htmlBody = [[NSString alloc] initWithFormat:@"<div class=\"logo\" style=\"text-indent:2em\"><font style=\"font-size:%@px;\">%@</font></div>",fontArray[fontIndex],[_dictionary objectForKey:@"desc"]];
85 87 NSString* htmlFooter = @"</body></html>";
86   - NSString* strHtml = [[NSString alloc] initWithFormat:@"%@%@%@%@%@%@",htmlHeader,htmldate,htmlForm,content,htmlBody,htmlFooter];
  88 + NSString* strHtml = [[NSString alloc] initWithFormat:@"%@%@%@%@%@%@%@",htmlHeader,htmldate,htmlForm,htmlBody,line,content,htmlFooter];
87 89 return strHtml;
88 90 }
89 91  
... ... @@ -94,7 +96,6 @@
94 96 [self.liveController stop];
95 97 self.liveController = nil;
96 98 self.videoController = nil;
97   - [_webView.scrollView removeObserver:self forKeyPath:@"contentSize" context:@"WebKitContext"];
98 99 NSLog(@"delloc");
99 100 }
100 101 - (void)loadShareView {
... ... @@ -235,12 +236,10 @@
235 236 WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
236 237 wkWebConfig.userContentController = wkUController;
237 238  
238   - _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 0) configuration:wkWebConfig];
  239 + _webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:wkWebConfig];
239 240 _webView.scrollView.backgroundColor = [UIColor clearColor];
240   -// _webView.dataDetectorTypes = UIDataDetectorTypeNone;
241 241 _webView.backgroundColor = [UIColor clearColor];
242 242 _webView.scrollView.bounces = NO;
243   -// _webView.delegate = self;
244 243 _webView.navigationDelegate = self;
245 244 _webView.UIDelegate = self;
246 245 _webView.opaque = NO;
... ... @@ -275,26 +274,8 @@
275 274 } else {
276 275 [self addZXVideo:movieUrl];
277 276 }
278   - [_webView.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:@"WebKitContext"];
279 277 }
280 278  
281   -- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
282   -
283   - if ([keyPath isEqualToString:@"contentSize"] && !_webView.loading && _webView.height != _webView.scrollView.contentSize.height) {
284   - CGRect frame = _webView.frame;
285   - frame.size.width = MainScreenWidth;
286   - frame.size.height = 1;
287   - CGFloat graphicLiveHeight = self->_webView.scrollView.contentSize.height;
288   - frame.size.height = _webView.scrollView.contentSize.height;
289   - NSLog(@"YYYYYYYYYYY%f",_webView.scrollView.contentSize.height);
290   - _webView.frame = frame;
291   - [heightArr replaceObjectAtIndex:fontIndex withObject:[NSString stringWithFormat:@"%f",graphicLiveHeight]];
292   - if (_newsArray.count != 0) {
293   - [self.tableView setFrame:CGRectMake(0, [heightArr[fontIndex] floatValue], MainScreenWidth, 36 + 86*_newsArray.count)];
294   - }
295   - [backgroundView setContentSize:CGSizeMake(MainScreenWidth, [heightArr[fontIndex] floatValue] + self.tableView.frame.size.height)];
296   - }
297   -}
298 279 // CNLivePlayer
299 280 - (void)addCNLivePlayer {
300 281  
... ... @@ -434,27 +415,19 @@
434 415 decisionHandler(WKNavigationActionPolicyAllow);
435 416 }
436 417 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation*)navigation {
437   - CGFloat width = MainScreenWidth - 20;
438   - NSString *string = [NSString stringWithFormat:
439   - @"var script = document.createElement('script');"
440   - "script.type = 'text/javascript';"
441   - "script.text = \"function ResizeImages() { "
442   - "var myimg,oldwidth;"
443   - "var maxwidth=%f;" //缩放系数
444   - "for(i=0;i <document.images.length;i++){"
445   - "myimg = document.images[i];"
446   - "if(myimg.width > maxwidth){"
447   - "oldwidth = myimg.width;"
448   - "myimg.width = maxwidth;"
449   - "myimg.height = myimg.height * (maxwidth/oldwidth);"
450   - "}"
451   - "}"
452   - "}\";"
453   - "document.getElementsByTagName('head')[0].appendChild(script);",width];
454   - [_webView evaluateJavaScript:@"ResizeImages();" completionHandler:nil];
455   - [_webView evaluateJavaScript:string completionHandler:^(id _Nullable response, NSError * _Nullable error) {
456   - NSLog(@"value: %@ error: %@", response, error);
457   -
  418 + CGRect frame = _webView.frame;
  419 + frame.size.width = MainScreenWidth;
  420 + frame.size.height = 1;
  421 + _webView.frame = frame;
  422 + [webView evaluateJavaScript:@"document.body.scrollHeight"completionHandler:^(id _Nullable result,NSError * _Nullable error){
  423 + NSLog(@"scrollHeight高度:%.2f",[result floatValue]);
  424 + CGFloat descriptionHeight = [result floatValue];
  425 + [self->_webView setFrame:CGRectMake(0, 0, MainScreenWidth, descriptionHeight)];
  426 + [self->heightArr replaceObjectAtIndex:fontIndex withObject:[NSString stringWithFormat:@"%f",descriptionHeight]];
  427 + if (self->_newsArray.count != 0) {
  428 + [self.tableView setFrame:CGRectMake(0, [heightArr[fontIndex] floatValue], MainScreenWidth, 36 + 86*_newsArray.count)];
  429 + }
  430 + [backgroundView setContentSize:CGSizeMake(MainScreenWidth, [heightArr[fontIndex] floatValue] + self.tableView.frame.size.height)];
458 431 }];
459 432  
460 433 }
... ...
CNLiveScioLive/Pages/Home/新闻详情/OldController/SCIOSpecialViewController.m
... ... @@ -329,6 +329,18 @@
329 329 label.textColor = HEXCOLOR(0x1959c9);
330 330 label.font = [UIFont systemFontOfSize:16.0];
331 331 label.text = dic[@"title"];
  332 + if ([dic[@"moreVisible"] isEqualToString:@"1"]) {
  333 + UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  334 + [button setTitle:dic[@"moreTitle"] forState:UIControlStateNormal];
  335 + [button setFrame:CGRectMake(MainScreenWidth - 122 , 10, 100, 40)];
  336 + button.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
  337 + button.tag = section;
  338 + [button setTitleColor:HEXCOLOR(0x1959C9) forState:UIControlStateNormal];
  339 + [button.titleLabel setFont: [UIFont systemFontOfSize:14.0f]];
  340 + [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
  341 + [view addSubview:button];
  342 + }else if ([dic[@"moreVisible"] isEqualToString:@"2"]){}
  343 + else{
332 344 if ([array count] > 4) {
333 345 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
334 346 [button setTitle:@"更多" forState:UIControlStateNormal];
... ... @@ -340,7 +352,7 @@
340 352 [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
341 353 [view addSubview:button];
342 354 }
343   -
  355 + }
344 356 [view addSubview:line];
345 357 [view addSubview:label];
346 358  
... ...
CNLiveScioLive/Pages/Tools/ImageGray/UIColor+CNGray.h 0 → 100644
  1 +//
  2 +// UIColor+CNGray.h
  3 +// CNLiveScioLive
  4 +//
  5 +// Created by CNLive on 2021/5/10.
  6 +// Copyright © 2021 CNLive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +
  13 +@interface UIColor (CNGray)
  14 +
  15 +@end
  16 +
  17 +NS_ASSUME_NONNULL_END
... ...
CNLiveScioLive/Pages/Tools/ImageGray/UIColor+CNGray.m 0 → 100644
  1 +//
  2 +// UIColor+CNGray.m
  3 +// CNLiveScioLive
  4 +//
  5 +// Created by CNLive on 2021/5/10.
  6 +// Copyright © 2021 CNLive. All rights reserved.
  7 +//
  8 +
  9 +#import "UIColor+CNGray.h"
  10 +
  11 +@implementation UIColor (CNGray)
  12 ++(void)load
  13 +{
  14 + static dispatch_once_t onceToken;
  15 + dispatch_once(&onceToken, ^{
  16 + Method setImage = class_getClassMethod(self,@selector(colorWithRed:green:blue:alpha:));
  17 + Method xmtSwizzledSetImage = class_getClassMethod(self,@selector(cn_colorWithRed:green:blue:alpha:));
  18 + ///交换IMP
  19 + method_exchangeImplementations(setImage, xmtSwizzledSetImage);
  20 + });
  21 +}
  22 ++ (UIColor *)cn_colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)a{
  23 + CGFloat gray = red*0.299 + green*0.587 + blue*0.114;
  24 + return [self cn_colorWithRed:gray green:gray blue:gray alpha:a];
  25 +}
  26 +@end
... ...
CNLiveScioLive/Pages/Tools/ImageGray/UIImage+CNGray.h 0 → 100644
  1 +//
  2 +// UIImage+CNGray.h
  3 +// CNLiveScioLive
  4 +//
  5 +// Created by CNLive on 2021/4/27.
  6 +// Copyright © 2021 CNLive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +
  13 +@interface UIImage (CNGray)
  14 +
  15 ++ (UIImage *)grayImage:( UIImage *)sourceImage;
  16 +
  17 +@end
  18 +
  19 +NS_ASSUME_NONNULL_END
... ...
CNLiveScioLive/Pages/Tools/ImageGray/UIImage+CNGray.m 0 → 100644
  1 +//
  2 +// UIImage+CNGray.m
  3 +// CNLiveScioLive
  4 +//
  5 +// Created by CNLive on 2021/4/27.
  6 +// Copyright © 2021 CNLive. All rights reserved.
  7 +//
  8 +
  9 +#import "UIImage+CNGray.h"
  10 +
  11 +@implementation UIImage (CNGray)
  12 ++ ( UIImage *)grayImage:( UIImage *)sourceImage {
  13 + const int RED = 1;
  14 + const int GREEN = 2;
  15 + const int BLUE = 3;
  16 + CGRect imageRect = CGRectMake(0, 0, sourceImage.size.width *sourceImage.scale, sourceImage.size.height *sourceImage.scale);
  17 + int width = imageRect.size.width;
  18 + int height = imageRect.size.height;
  19 + uint32_t *pisels = (uint32_t *)malloc(width*height *sizeof(uint32_t));
  20 + memset(pisels, 0, width *height *sizeof(uint32_t));
  21 + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  22 + CGContextRef context = CGBitmapContextCreate(pisels, width, height, 8, width *sizeof(uint32_t), colorSpace, kCGBitmapByteOrder32Little|kCGImageAlphaPremultipliedLast);
  23 + CGContextDrawImage(context, CGRectMake(0, 0, width, height), [sourceImage CGImage]);
  24 + for (int y = 0; y < height; y ++) {
  25 + for (int x = 0; x<width; x++) {
  26 + uint8_t *rgbaPixel = (uint8_t *)&pisels[y*width +x];
  27 + uint32_t gray = 0.3 *rgbaPixel[RED] + 0.59 *rgbaPixel[GREEN] + 0.11 *rgbaPixel[BLUE];
  28 + rgbaPixel[RED] = gray;
  29 + rgbaPixel[GREEN] = gray;
  30 + rgbaPixel[BLUE] = gray;
  31 +
  32 + }
  33 + }
  34 + CGImageRef imageRef = CGBitmapContextCreateImage(context);
  35 + CGContextRelease(context);
  36 + CGColorSpaceRelease(colorSpace);
  37 + free(pisels);
  38 + UIImage *resultImage = [UIImage imageWithCGImage:imageRef scale:sourceImage.scale orientation:UIImageOrientationUp];
  39 + CGImageRelease(imageRef);
  40 + return resultImage;
  41 +}
  42 +@end
... ...
CNLiveScioLive/Pages/Tools/ImageGray/UIImageView+CNGrayImage.h 0 → 100644
  1 +//
  2 +// UIImageView+CNGrayImage.h
  3 +// CNLiveScioLive
  4 +//
  5 +// Created by CNLive on 2021/4/27.
  6 +// Copyright © 2021 CNLive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +
  13 +@interface UIImageView (CNGrayImage)
  14 +
  15 +@end
  16 +
  17 +NS_ASSUME_NONNULL_END
... ...
CNLiveScioLive/Pages/Tools/ImageGray/UIImageView+CNGrayImage.m 0 → 100644
  1 +//
  2 +// UIImageView+CNGrayImage.m
  3 +// CNLiveScioLive
  4 +//
  5 +// Created by CNLive on 2021/4/27.
  6 +// Copyright © 2021 CNLive. All rights reserved.
  7 +//
  8 +
  9 +#import "UIImageView+CNGrayImage.h"
  10 +#import <objc/runtime.h>
  11 +#import "UIImage+CNGray.m"
  12 +
  13 +@implementation UIImageView (CNGrayImage)
  14 ++(void)load
  15 +{
  16 + static dispatch_once_t onceToken;
  17 + dispatch_once(&onceToken, ^{
  18 + Method setImage = class_getInstanceMethod(self,@selector(setImage:));
  19 + Method xmtSwizzledSetImage = class_getInstanceMethod(self,@selector(xmtSwizzledSetImage:));
  20 + ///交换IMP
  21 + method_exchangeImplementations(setImage, xmtSwizzledSetImage);
  22 + });
  23 +}
  24 +- (void)xmtSwizzledSetImage:(UIImage *)image {
  25 +
  26 + /// 图片使用灰白处理
  27 + image = [UIImage grayImage:image];
  28 + [self xmtSwizzledSetImage:image];
  29 +}
  30 +@end
... ...
CNLiveScioLive/Pages/Tools/ImageGray/WKWebView+CNGray.h 0 → 100644
  1 +//
  2 +// WKWebView+CNGray.h
  3 +// CNLiveScioLive
  4 +//
  5 +// Created by CNLive on 2021/5/10.
  6 +// Copyright © 2021 CNLive. All rights reserved.
  7 +//
  8 +
  9 +#import <WebKit/WebKit.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +
  13 +@interface WKWebView (CNGray)
  14 +
  15 +@end
  16 +
  17 +NS_ASSUME_NONNULL_END
... ...
CNLiveScioLive/Pages/Tools/ImageGray/WKWebView+CNGray.m 0 → 100644
  1 +//
  2 +// WKWebView+CNGray.m
  3 +// CNLiveScioLive
  4 +//
  5 +// Created by CNLive on 2021/5/10.
  6 +// Copyright © 2021 CNLive. All rights reserved.
  7 +//
  8 +
  9 +#import "WKWebView+CNGray.h"
  10 +
  11 +@implementation WKWebView (CNGray)
  12 ++(void)load
  13 +{
  14 + static dispatch_once_t onceToken;
  15 + dispatch_once(&onceToken, ^{
  16 + Method setImage = class_getInstanceMethod(self,@selector(initWithFrame:configuration:));
  17 + Method xmtSwizzledSetImage = class_getInstanceMethod(self,@selector(cn_initWithFrame:configuration:));
  18 + ///交换IMP
  19 + method_exchangeImplementations(setImage, xmtSwizzledSetImage);
  20 + });
  21 +}
  22 +- (instancetype)cn_initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration {
  23 + // js脚本
  24 + NSString *jScript = @"var filter = '-webkit-filter:grayscale(100%);-moz-filter:grayscale(100%); -ms-filter:grayscale(100%); -o-filter:grayscale(100%) filter:grayscale(100%);';document.getElementsByTagName('html')[0].style.filter = 'grayscale(100%)';meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width, user-scalable=no'); document.getElementsByTagName('head')[0].appendChild(meta);";
  25 + // 注入
  26 + WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
  27 +
  28 + WKUserContentController *wkUController = [[WKUserContentController alloc] init];
  29 + [wkUController addUserScript:wkUScript];
  30 + // 配置对象
  31 + WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
  32 + wkWebConfig.userContentController = wkUController;
  33 + configuration = wkWebConfig;
  34 + WKWebView *webView = [self cn_initWithFrame:frame configuration:configuration];
  35 + return webView;
  36 +}
  37 +@end
... ...