Commit f2a0117a9c251f531b357325471bab57493ed320
1 parent
6cf65aae
移除UIWebView , 替换为WKWebView
Showing
7 changed files
with
154 additions
and
146 deletions
CNLiveScioLive/Pages/Home/新闻详情/Controller/VideoDetailViewController.m
| ... | ... | @@ -418,7 +418,7 @@ static NSString *newsLeftPicTableViewCell = @"CNLiveNewsLeftPicTableViewCell"; |
| 418 | 418 | } |
| 419 | 419 | decisionHandler(WKNavigationActionPolicyAllow); |
| 420 | 420 | } |
| 421 | -//- (void)webViewDidFinishLoad:(UIWebView *)webView{ | |
| 421 | +//- (void)webViewDidFinishLoad:(IWebView *)webView{ | |
| 422 | 422 | // CGFloat width = MainScreenWidth - 20; |
| 423 | 423 | // NSString *string = [NSString stringWithFormat: |
| 424 | 424 | // @"var script = document.createElement('script');" | ... | ... |
CNLiveScioLive/Pages/Live/Controller/GraphicLiveViewController.h
| ... | ... | @@ -18,15 +18,15 @@ typedef NS_ENUM(NSInteger, PlayerType) { |
| 18 | 18 | PlayerTypeNormal // 普通URL模式 |
| 19 | 19 | }; |
| 20 | 20 | |
| 21 | -@interface GraphicLiveViewController : CNLiveBaseViewController<UIWebViewDelegate>{ | |
| 21 | +@interface GraphicLiveViewController : CNLiveBaseViewController<WKNavigationDelegate>{ | |
| 22 | 22 | UIScrollView *backgroundView; |
| 23 | 23 | UIImageView *imageView; |
| 24 | 24 | UIButton *playBtn; |
| 25 | 25 | NSURL *movieUrl; |
| 26 | 26 | NSString *url; |
| 27 | 27 | |
| 28 | - UIWebView *relatedWebView; | |
| 29 | - UIWebView *_webView; | |
| 28 | + WKWebView *relatedWebView; | |
| 29 | + WKWebView *_webView; | |
| 30 | 30 | NSArray *_newsArray; |
| 31 | 31 | CGFloat videoHeight; |
| 32 | 32 | CGFloat descriptionHeight; | ... | ... |
CNLiveScioLive/Pages/Live/Controller/GraphicLiveViewController.m
| ... | ... | @@ -117,12 +117,12 @@ |
| 117 | 117 | backgroundView.bounces = NO; |
| 118 | 118 | [self.view addSubview:backgroundView]; |
| 119 | 119 | |
| 120 | - relatedWebView = [[UIWebView alloc] initWithFrame:CGRectZero]; | |
| 120 | + relatedWebView = [[WKWebView alloc] initWithFrame:CGRectZero]; | |
| 121 | 121 | relatedWebView.scrollView.backgroundColor = [UIColor whiteColor]; |
| 122 | - relatedWebView.dataDetectorTypes = UIDataDetectorTypeNone; | |
| 122 | +// relatedWebView.dataDetectorTypes = UIDataDetectorTypeNone; | |
| 123 | 123 | relatedWebView.backgroundColor = [UIColor whiteColor]; |
| 124 | 124 | relatedWebView.scrollView.bounces = NO; |
| 125 | - relatedWebView.delegate = self; | |
| 125 | + relatedWebView.navigationDelegate = self; | |
| 126 | 126 | relatedWebView.opaque = NO; |
| 127 | 127 | relatedWebView.tag = 1000; |
| 128 | 128 | [backgroundView addSubview:relatedWebView]; |
| ... | ... | @@ -132,11 +132,11 @@ |
| 132 | 132 | NSString* strHtml = [[NSString alloc] initWithFormat:@"%@%@",htmlHeader,htmlFooter]; |
| 133 | 133 | [relatedWebView loadHTMLString:strHtml baseURL:nil]; |
| 134 | 134 | |
| 135 | - _webView = [[UIWebView alloc] initWithFrame:CGRectZero]; | |
| 135 | + _webView = [[WKWebView alloc] initWithFrame:CGRectZero]; | |
| 136 | 136 | _webView.scrollView.backgroundColor = [UIColor whiteColor]; |
| 137 | - _webView.dataDetectorTypes = UIDataDetectorTypeNone; | |
| 137 | +// _webView.dataDetectorTypes = UIDataDetectorTypeNone; | |
| 138 | 138 | _webView.backgroundColor = [UIColor whiteColor]; |
| 139 | - _webView.delegate = self; | |
| 139 | + _webView.navigationDelegate = self; | |
| 140 | 140 | _webView.opaque = NO; |
| 141 | 141 | _webView.tag = 2000; |
| 142 | 142 | _webView.hidden = YES; |
| ... | ... | @@ -275,16 +275,23 @@ |
| 275 | 275 | [[UIApplication sharedApplication] setStatusBarHidden:Bool withAnimation:UIStatusBarAnimationFade]; |
| 276 | 276 | [self.navigationController setNavigationBarHidden:Bool]; |
| 277 | 277 | } |
| 278 | -- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ | |
| 279 | - NSURL *requestURL =[request URL]; | |
| 280 | - if (([[requestURL scheme] isEqualToString: @"http"] || [[requestURL scheme] isEqualToString:@"https"] || [[requestURL scheme] isEqualToString: @"mailto" ]) && (navigationType == UIWebViewNavigationTypeLinkClicked)) { | |
| 281 | - [[UIApplication sharedApplication] openURL:[request URL]]; | |
| 282 | - return NO; | |
| 278 | + | |
| 279 | +#pragma mark - WKNavigationDelegate | |
| 280 | +// 页面开始加载时调用 | |
| 281 | +- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler | |
| 282 | +{ | |
| 283 | + NSURL *requestURL = navigationAction.request.URL; | |
| 284 | + NSString *scheme = navigationAction.request.URL.scheme; | |
| 285 | + if (([scheme isEqualToString: @"http"] || [scheme isEqualToString:@"https"] || [scheme isEqualToString: @"mailto" ]) && (navigationAction.navigationType == WKNavigationTypeLinkActivated )) { | |
| 286 | + [[UIApplication sharedApplication] openURL:requestURL]; | |
| 287 | + decisionHandler(WKNavigationActionPolicyCancel); | |
| 283 | 288 | } |
| 284 | - return YES; | |
| 289 | + decisionHandler(WKNavigationActionPolicyAllow); | |
| 285 | 290 | } |
| 286 | 291 | |
| 287 | -- (void)webViewDidFinishLoad:(UIWebView *)webView{ | |
| 292 | +// 页面加载完成之后调用 | |
| 293 | +- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation | |
| 294 | +{ | |
| 288 | 295 | |
| 289 | 296 | if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) { |
| 290 | 297 | [self setUpUIWithTag:webView.tag Height:0]; |
| ... | ... | @@ -342,12 +349,12 @@ |
| 342 | 349 | |
| 343 | 350 | [backgroundView setContentSize:CGSizeMake(MainScreenWidth, height + descriptionHeight + 960)]; |
| 344 | 351 | |
| 345 | - _webView = [[UIWebView alloc] initWithFrame:CGRectZero]; | |
| 352 | + _webView = [[WKWebView alloc] initWithFrame:CGRectZero]; | |
| 346 | 353 | _webView.scrollView.backgroundColor = [UIColor clearColor]; |
| 347 | - _webView.dataDetectorTypes = UIDataDetectorTypeNone; | |
| 354 | +// _webView.dataDetectorTypes = UIDataDetectorTypeNone; | |
| 348 | 355 | _webView.backgroundColor = [UIColor clearColor]; |
| 349 | 356 | _webView.scrollView.bounces = NO; |
| 350 | - _webView.delegate = self; | |
| 357 | + _webView.navigationDelegate = self; | |
| 351 | 358 | _webView.hidden = YES; |
| 352 | 359 | _webView.opaque = NO; |
| 353 | 360 | _webView.tag = 2000; |
| ... | ... | @@ -377,8 +384,11 @@ |
| 377 | 384 | "}" |
| 378 | 385 | "}\";" |
| 379 | 386 | "document.getElementsByTagName('head')[0].appendChild(script);",width]; |
| 380 | - [_webView stringByEvaluatingJavaScriptFromString:string]; | |
| 381 | - [_webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"]; | |
| 387 | +// [_webView stringByEvaluatingJavaScriptFromString:string]; | |
| 388 | +// [_webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"]; | |
| 389 | + | |
| 390 | + [_webView evaluateJavaScript:string completionHandler:nil]; | |
| 391 | + [_webView evaluateJavaScript:@"ResizeImages();" completionHandler:nil]; | |
| 382 | 392 | |
| 383 | 393 | CGRect frame = _webView.frame; |
| 384 | 394 | frame.size.width = MainScreenWidth; |
| ... | ... | @@ -400,8 +410,7 @@ |
| 400 | 410 | } |
| 401 | 411 | } |
| 402 | 412 | } |
| 403 | -- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{ | |
| 404 | -} | |
| 413 | + | |
| 405 | 414 | - (void)showRelatedInformation:(CGFloat)y { |
| 406 | 415 | for (UIView *view in relatedInformationView.subviews) { |
| 407 | 416 | [view removeFromSuperview]; | ... | ... |
CNLiveScioLive/Pages/Live/Controller/TopNoticeViewController.h
| ... | ... | @@ -8,8 +8,8 @@ |
| 8 | 8 | |
| 9 | 9 | #import <UIKit/UIKit.h> |
| 10 | 10 | #import "CNLiveBaseViewController.h" |
| 11 | -@interface TopNoticeViewController : CNLiveBaseViewController<UIWebViewDelegate>{ | |
| 12 | - UIWebView *_webView; | |
| 11 | +@interface TopNoticeViewController : CNLiveBaseViewController<WKNavigationDelegate>{ | |
| 12 | + WKWebView *_webView; | |
| 13 | 13 | NSDictionary *_dictionary; |
| 14 | 14 | } |
| 15 | 15 | @end | ... | ... |
CNLiveScioLive/Pages/Live/Controller/TopNoticeViewController.m
| ... | ... | @@ -10,7 +10,7 @@ |
| 10 | 10 | //#import <ShareSDKUI/ShareSDK+SSUI.h> |
| 11 | 11 | //#import <ShareSDK/ShareSDK.h> |
| 12 | 12 | |
| 13 | -@interface TopNoticeViewController ()<UIWebViewDelegate> | |
| 13 | +@interface TopNoticeViewController ()<WKNavigationDelegate> | |
| 14 | 14 | @property (nonatomic, strong) NSArray *fontArray; |
| 15 | 15 | @property (nonatomic, assign) NSInteger fontIndex; |
| 16 | 16 | |
| ... | ... | @@ -106,15 +106,15 @@ |
| 106 | 106 | } |
| 107 | 107 | - (void)setUpUI{ |
| 108 | 108 | if (iPhoneX) { |
| 109 | - _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - 88 - 44 - 34)]; | |
| 109 | + _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - 88 - 44 - 34)]; | |
| 110 | 110 | } else { |
| 111 | - _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - 64 - 44)]; | |
| 111 | + _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - 64 - 44)]; | |
| 112 | 112 | } |
| 113 | 113 | _webView.scrollView.backgroundColor = [UIColor whiteColor]; |
| 114 | 114 | _webView.backgroundColor = [UIColor whiteColor]; |
| 115 | 115 | // _webView.scalesPageToFit = YES; |
| 116 | 116 | _webView.opaque = NO; |
| 117 | - _webView.delegate = self; | |
| 117 | + _webView.navigationDelegate = self; | |
| 118 | 118 | [self.view addSubview:_webView]; |
| 119 | 119 | |
| 120 | 120 | } |
| ... | ... | @@ -122,16 +122,6 @@ |
| 122 | 122 | [super didReceiveMemoryWarning]; |
| 123 | 123 | // Dispose of any resources that can be recreated. |
| 124 | 124 | } |
| 125 | -#pragma mark - UIWebViewDelegate | |
| 126 | -- (void)webViewDidStartLoad:(UIWebView *)webView{ | |
| 127 | - | |
| 128 | -} | |
| 129 | -- (void)webViewDidFinishLoad:(UIWebView *)webView{ | |
| 130 | - | |
| 131 | -} | |
| 132 | -- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{ | |
| 133 | - | |
| 134 | -} | |
| 135 | 125 | |
| 136 | 126 | - (void)loadShareView { |
| 137 | 127 | UIImageView *lineImage = [[UIImageView alloc] init]; |
| ... | ... | @@ -194,11 +184,14 @@ |
| 194 | 184 | _fontIndex++; |
| 195 | 185 | } |
| 196 | 186 | if (0 == _fontIndex) { |
| 197 | - [_webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '100%'"]; | |
| 187 | +// [_webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '100%'"]; | |
| 188 | + [_webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '100%'" completionHandler:nil]; | |
| 198 | 189 | } else if (1 == _fontIndex) { |
| 199 | - [_webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '120%'"]; | |
| 190 | +// [_webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '120%'"]; | |
| 191 | + [_webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '120%'" completionHandler:nil]; | |
| 200 | 192 | } else if (2 == _fontIndex) { |
| 201 | - [_webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '140%'"]; | |
| 193 | +// [_webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '140%'"]; | |
| 194 | + [_webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '140%'" completionHandler:nil]; | |
| 202 | 195 | } |
| 203 | 196 | } else if (20000 == btn.tag) { |
| 204 | 197 | TableData *notice = [[TableData alloc] initWithJSONDictionary:_dictionary[@"programs"][0]]; | ... | ... |
CNLiveScioLive/Pages/Live/Controller/VideoPlayBackViewController.h
| ... | ... | @@ -11,15 +11,15 @@ |
| 11 | 11 | #import <MediaPlayer/MediaPlayer.h> |
| 12 | 12 | #import "ZXVideoPlayerController.h" |
| 13 | 13 | #import "CNLivePlayerController.h" |
| 14 | -@interface VideoPlayBackViewController : BaseViewController<UITableViewDelegate,UITableViewDataSource,UIWebViewDelegate>{ | |
| 14 | +@interface VideoPlayBackViewController : BaseViewController<UITableViewDelegate,UITableViewDataSource,WKNavigationDelegate>{ | |
| 15 | 15 | UIScrollView *backgroundView; |
| 16 | 16 | UIImageView *imageView; |
| 17 | 17 | UIButton *playBtn; |
| 18 | 18 | NSURL *movieUrl; |
| 19 | 19 | NSString *url; |
| 20 | 20 | |
| 21 | - UIWebView *relatedWebView; | |
| 22 | - UIWebView *_webView; | |
| 21 | + WKWebView *relatedWebView; | |
| 22 | + WKWebView *_webView; | |
| 23 | 23 | NSArray *_newsArray; |
| 24 | 24 | CGFloat videoHeight; |
| 25 | 25 | CGFloat descriptionHeight; | ... | ... |
CNLiveScioLive/Pages/Live/Controller/VideoPlayBackViewController.m
| ... | ... | @@ -225,12 +225,12 @@ |
| 225 | 225 | } |
| 226 | 226 | backgroundView.bounces = NO; |
| 227 | 227 | [self.view addSubview:backgroundView]; |
| 228 | - relatedWebView = [[UIWebView alloc] initWithFrame:CGRectZero]; | |
| 228 | + relatedWebView = [[WKWebView alloc] initWithFrame:CGRectZero]; | |
| 229 | 229 | relatedWebView.scrollView.backgroundColor = [UIColor whiteColor]; |
| 230 | - relatedWebView.dataDetectorTypes = UIDataDetectorTypeNone; | |
| 230 | +// relatedWebView.dataDetectorTypes = UIDataDetectorTypeNone; | |
| 231 | 231 | relatedWebView.backgroundColor = [UIColor whiteColor]; |
| 232 | 232 | relatedWebView.scrollView.bounces = NO; |
| 233 | - relatedWebView.delegate = self; | |
| 233 | + relatedWebView.navigationDelegate = self; | |
| 234 | 234 | relatedWebView.opaque = NO; |
| 235 | 235 | relatedWebView.tag = 1000; |
| 236 | 236 | [backgroundView addSubview:relatedWebView]; |
| ... | ... | @@ -387,108 +387,114 @@ |
| 387 | 387 | _webView.hidden = YES; |
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | -- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ | |
| 391 | - NSURL *requestURL =[request URL]; | |
| 392 | - if (([[requestURL scheme] isEqualToString: @"http"] || [[requestURL scheme] isEqualToString:@"https"] || [[requestURL scheme] isEqualToString: @"mailto" ]) && (navigationType == UIWebViewNavigationTypeLinkClicked)) { | |
| 393 | - [[UIApplication sharedApplication] openURL:[request URL]]; | |
| 394 | - return NO; | |
| 390 | + | |
| 391 | +#pragma mark - WKNavigationDelegate | |
| 392 | +// 页面开始加载时调用 | |
| 393 | +- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler | |
| 394 | +{ | |
| 395 | + NSURL *requestURL = navigationAction.request.URL; | |
| 396 | + NSString *scheme = navigationAction.request.URL.scheme; | |
| 397 | + if (([scheme isEqualToString: @"http"] || [scheme isEqualToString:@"https"] || [scheme isEqualToString: @"mailto" ]) && (navigationAction.navigationType == WKNavigationTypeLinkActivated )) { | |
| 398 | + [[UIApplication sharedApplication] openURL:requestURL]; | |
| 399 | + decisionHandler(WKNavigationActionPolicyCancel); | |
| 395 | 400 | } |
| 396 | - return YES; | |
| 401 | + decisionHandler(WKNavigationActionPolicyAllow); | |
| 397 | 402 | } |
| 398 | -- (void)webViewDidFinishLoad:(UIWebView *)webView{ | |
| 403 | +// 页面加载完成之后调用 | |
| 404 | +- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation | |
| 405 | +{ | |
| 399 | 406 | if (1000 == webView.tag) { |
| 400 | - CGRect frame = relatedWebView.frame; | |
| 401 | - frame.size.width = MainScreenWidth; | |
| 402 | - frame.size.height = 1; | |
| 403 | - relatedWebView.frame = frame; | |
| 404 | - descriptionHeight = relatedWebView.scrollView.contentSize.height; | |
| 405 | - [relatedWebView setFrame:CGRectMake(0, 0, MainScreenWidth, descriptionHeight)]; | |
| 406 | - lineImage1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, descriptionHeight, MainScreenWidth, 1)]; | |
| 407 | - lineImage1.backgroundColor = Color_Line; | |
| 408 | - [backgroundView addSubview:lineImage1]; | |
| 409 | - | |
| 410 | - upDownButton = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 411 | - [upDownButton addTarget:self action:@selector(showGraphicLive:) forControlEvents:UIControlEventTouchUpInside]; | |
| 412 | - [upDownButton setFrame:CGRectMake(0, descriptionHeight, MainScreenWidth, 40)]; | |
| 413 | - [backgroundView addSubview:upDownButton]; | |
| 414 | - | |
| 415 | - UILabel *graphicLive = [[UILabel alloc] initWithFrame:CGRectMake(20, descriptionHeight, MainScreenWidth/2, 40)]; | |
| 416 | - graphicLive.font = [UIFont systemFontOfSize:13]; | |
| 417 | - graphicLive.backgroundColor = [UIColor clearColor]; | |
| 418 | - graphicLive.textColor = HEXCOLOR(0x184085); | |
| 419 | - [backgroundView addSubview:graphicLive]; | |
| 420 | - graphicLive.text = @"发布会图文播报"; | |
| 421 | - | |
| 422 | - upDownImage = [[UIImageView alloc] initWithFrame:CGRectMake(MainScreenWidth - 31, descriptionHeight + 16, 13, 7)]; | |
| 423 | - upDownImage.image = [UIImage imageNamed:@"cnlive_button_down"]; | |
| 424 | - [backgroundView addSubview:upDownImage]; | |
| 425 | - | |
| 426 | - lineImage2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40 + descriptionHeight, MainScreenWidth, 1)]; | |
| 427 | - lineImage2.backgroundColor = Color_Line; | |
| 428 | - [backgroundView addSubview:lineImage2]; | |
| 429 | - | |
| 430 | - [backgroundView setContentSize:CGSizeMake(MainScreenWidth, 40 + descriptionHeight)]; | |
| 431 | - | |
| 432 | - _webView = [[UIWebView alloc] initWithFrame:CGRectZero]; | |
| 433 | - _webView.scrollView.backgroundColor = [UIColor clearColor]; | |
| 434 | - _webView.dataDetectorTypes = UIDataDetectorTypeNone; | |
| 435 | - _webView.backgroundColor = [UIColor clearColor]; | |
| 436 | - _webView.scrollView.bounces = NO; | |
| 437 | - _webView.delegate = self; | |
| 438 | - | |
| 439 | - _webView.opaque = NO; | |
| 440 | - _webView.tag = 2000; | |
| 441 | - | |
| 442 | - [backgroundView addSubview:_webView]; | |
| 443 | - [self loadRelatedInformation]; | |
| 444 | - [self loadData]; | |
| 445 | - } | |
| 446 | - else if (2000 == webView.tag) { | |
| 447 | - CGFloat width = MainScreenWidth - 20; | |
| 448 | - NSString *string = [NSString stringWithFormat: | |
| 449 | - @"var script = document.createElement('script');" | |
| 450 | - "script.type = 'text/javascript';" | |
| 451 | - "script.text = \"function ResizeImages() { " | |
| 452 | - "var myimg,oldwidth;" | |
| 453 | - "var maxwidth=%f;" //缩放系数 | |
| 454 | - "for(i=0;i <document.images.length;i++){" | |
| 455 | - "myimg = document.images[i];" | |
| 456 | - "if(myimg.width > maxwidth){" | |
| 457 | - "oldwidth = myimg.width;" | |
| 458 | - "myimg.width = maxwidth;" | |
| 459 | - "myimg.height = myimg.height * (maxwidth/oldwidth);" | |
| 460 | - "}" | |
| 461 | - "}" | |
| 462 | - "}\";" | |
| 463 | - "document.getElementsByTagName('head')[0].appendChild(script);",width]; | |
| 464 | - [webView stringByEvaluatingJavaScriptFromString:string]; | |
| 465 | - [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"]; | |
| 466 | - | |
| 467 | - CGRect frame = _webView.frame; | |
| 468 | - frame.size.width = MainScreenWidth; | |
| 469 | - frame.size.height = 1; | |
| 470 | - _webView.frame = frame; | |
| 471 | - graphicLiveHeight = _webView.scrollView.contentSize.height; | |
| 472 | - | |
| 473 | - NSLog(@"%@",NSStringFromCGRect(_webView.frame)); | |
| 474 | - NSLog(@"%@",NSStringFromCGSize(_webView.scrollView.contentSize)); | |
| 475 | - if (0 == [heightArr[fontIndex] floatValue]) { | |
| 476 | - [heightArr replaceObjectAtIndex:fontIndex withObject:[NSString stringWithFormat:@"%f",graphicLiveHeight]]; | |
| 407 | + CGRect frame = relatedWebView.frame; | |
| 408 | + frame.size.width = MainScreenWidth; | |
| 409 | + frame.size.height = 1; | |
| 410 | + relatedWebView.frame = frame; | |
| 411 | + descriptionHeight = relatedWebView.scrollView.contentSize.height; | |
| 412 | + [relatedWebView setFrame:CGRectMake(0, 0, MainScreenWidth, descriptionHeight)]; | |
| 413 | + lineImage1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, descriptionHeight, MainScreenWidth, 1)]; | |
| 414 | + lineImage1.backgroundColor = Color_Line; | |
| 415 | + [backgroundView addSubview:lineImage1]; | |
| 416 | + | |
| 417 | + upDownButton = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 418 | + [upDownButton addTarget:self action:@selector(showGraphicLive:) forControlEvents:UIControlEventTouchUpInside]; | |
| 419 | + [upDownButton setFrame:CGRectMake(0, descriptionHeight, MainScreenWidth, 40)]; | |
| 420 | + [backgroundView addSubview:upDownButton]; | |
| 421 | + | |
| 422 | + UILabel *graphicLive = [[UILabel alloc] initWithFrame:CGRectMake(20, descriptionHeight, MainScreenWidth/2, 40)]; | |
| 423 | + graphicLive.font = [UIFont systemFontOfSize:13]; | |
| 424 | + graphicLive.backgroundColor = [UIColor clearColor]; | |
| 425 | + graphicLive.textColor = HEXCOLOR(0x184085); | |
| 426 | + [backgroundView addSubview:graphicLive]; | |
| 427 | + graphicLive.text = @"发布会图文播报"; | |
| 428 | + | |
| 429 | + upDownImage = [[UIImageView alloc] initWithFrame:CGRectMake(MainScreenWidth - 31, descriptionHeight + 16, 13, 7)]; | |
| 430 | + upDownImage.image = [UIImage imageNamed:@"cnlive_button_down"]; | |
| 431 | + [backgroundView addSubview:upDownImage]; | |
| 432 | + | |
| 433 | + lineImage2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40 + descriptionHeight, MainScreenWidth, 1)]; | |
| 434 | + lineImage2.backgroundColor = Color_Line; | |
| 435 | + [backgroundView addSubview:lineImage2]; | |
| 436 | + | |
| 437 | + [backgroundView setContentSize:CGSizeMake(MainScreenWidth, 40 + descriptionHeight)]; | |
| 438 | + | |
| 439 | + _webView = [[WKWebView alloc] initWithFrame:CGRectZero]; | |
| 440 | + _webView.scrollView.backgroundColor = [UIColor clearColor]; | |
| 441 | + // _webView.dataDetectorTypes = UIDataDetectorTypeNone; | |
| 442 | + _webView.backgroundColor = [UIColor clearColor]; | |
| 443 | + _webView.scrollView.bounces = NO; | |
| 444 | + _webView.UIDelegate = self; | |
| 445 | + | |
| 446 | + _webView.opaque = NO; | |
| 447 | + _webView.tag = 2000; | |
| 448 | + | |
| 449 | + [backgroundView addSubview:_webView]; | |
| 450 | + [self loadRelatedInformation]; | |
| 451 | + [self loadData]; | |
| 477 | 452 | } |
| 478 | - | |
| 479 | - if (isShow) { | |
| 480 | - NSLog(@"fontIndex = %d",fontIndex); | |
| 481 | - [backgroundView setContentSize:CGSizeMake(MainScreenWidth, 40 + descriptionHeight + [heightArr[fontIndex] floatValue] + 285)]; | |
| 482 | - [_webView setFrame:CGRectMake(0, 40 + descriptionHeight, MainScreenWidth, [heightArr[fontIndex] floatValue])]; | |
| 483 | - CGRect frame = self.tableView.frame; | |
| 484 | - frame.origin.y = 40 + descriptionHeight + graphicLiveHeight; | |
| 485 | - [self.tableView setFrame:frame]; | |
| 486 | - _webView.hidden = NO; | |
| 453 | + else if (2000 == webView.tag) { | |
| 454 | + CGFloat width = MainScreenWidth - 20; | |
| 455 | + NSString *string = [NSString stringWithFormat: | |
| 456 | + @"var script = document.createElement('script');" | |
| 457 | + "script.type = 'text/javascript';" | |
| 458 | + "script.text = \"function ResizeImages() { " | |
| 459 | + "var myimg,oldwidth;" | |
| 460 | + "var maxwidth=%f;" //缩放系数 | |
| 461 | + "for(i=0;i <document.images.length;i++){" | |
| 462 | + "myimg = document.images[i];" | |
| 463 | + "if(myimg.width > maxwidth){" | |
| 464 | + "oldwidth = myimg.width;" | |
| 465 | + "myimg.width = maxwidth;" | |
| 466 | + "myimg.height = myimg.height * (maxwidth/oldwidth);" | |
| 467 | + "}" | |
| 468 | + "}" | |
| 469 | + "}\";" | |
| 470 | + "document.getElementsByTagName('head')[0].appendChild(script);",width]; | |
| 471 | +// [webView stringByEvaluatingJavaScriptFromString:string]; | |
| 472 | +// [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"]; | |
| 473 | + [webView evaluateJavaScript:string completionHandler:nil]; | |
| 474 | + [webView evaluateJavaScript:@"ResizeImages();" completionHandler:nil]; | |
| 475 | + | |
| 476 | + CGRect frame = _webView.frame; | |
| 477 | + frame.size.width = MainScreenWidth; | |
| 478 | + frame.size.height = 1; | |
| 479 | + _webView.frame = frame; | |
| 480 | + graphicLiveHeight = _webView.scrollView.contentSize.height; | |
| 481 | + | |
| 482 | + NSLog(@"%@",NSStringFromCGRect(_webView.frame)); | |
| 483 | + NSLog(@"%@",NSStringFromCGSize(_webView.scrollView.contentSize)); | |
| 484 | + if (0 == [heightArr[fontIndex] floatValue]) { | |
| 485 | + [heightArr replaceObjectAtIndex:fontIndex withObject:[NSString stringWithFormat:@"%f",graphicLiveHeight]]; | |
| 486 | + } | |
| 487 | + | |
| 488 | + if (isShow) { | |
| 489 | + NSLog(@"fontIndex = %d",fontIndex); | |
| 490 | + [backgroundView setContentSize:CGSizeMake(MainScreenWidth, 40 + descriptionHeight + [heightArr[fontIndex] floatValue] + 285)]; | |
| 491 | + [_webView setFrame:CGRectMake(0, 40 + descriptionHeight, MainScreenWidth, [heightArr[fontIndex] floatValue])]; | |
| 492 | + CGRect frame = self.tableView.frame; | |
| 493 | + frame.origin.y = 40 + descriptionHeight + graphicLiveHeight; | |
| 494 | + [self.tableView setFrame:frame]; | |
| 495 | + _webView.hidden = NO; | |
| 496 | + } | |
| 487 | 497 | } |
| 488 | - } | |
| 489 | -} | |
| 490 | -- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{ | |
| 491 | - | |
| 492 | 498 | } |
| 493 | 499 | |
| 494 | 500 | - (void)shareButtonCNLivePlayerController:(CNLivePlayerController *)view{ | ... | ... |