Commit 416514ba282163f1d20b223f75fe82ddd2823cff
1 parent
f4ae3d57
no message
Showing
2 changed files
with
101 additions
and
115 deletions
CNLiveScioLive/Pages/Home/CNHomeBaseViewController.m
| @@ -267,32 +267,6 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | @@ -267,32 +267,6 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; | ||
| 267 | */ | 267 | */ |
| 268 | #pragma mark - Action | 268 | #pragma mark - Action |
| 269 | - (void)pushViewControllerWithModel:(CNHomeModel *)model { | 269 | - (void)pushViewControllerWithModel:(CNHomeModel *)model { |
| 270 | -// if ([model.type isEqualToString:@"program"]) { | ||
| 271 | -// //视频 | ||
| 272 | -// VideoDetailViewController *vc = [[VideoDetailViewController alloc] init]; | ||
| 273 | -// vc.model = model; | ||
| 274 | -// vc.hidesBottomBarWhenPushed = YES; | ||
| 275 | -// [self.navigationController pushViewController:vc animated:YES]; | ||
| 276 | -// | ||
| 277 | -// } else if ([model.type isEqualToString:@"article"]) { | ||
| 278 | -// //文章 | ||
| 279 | -// ArticleDetailViewController *vc = [[ArticleDetailViewController alloc] init]; | ||
| 280 | -// vc.model = model; | ||
| 281 | -// vc.hidesBottomBarWhenPushed = YES; | ||
| 282 | -// [self.navigationController pushViewController:vc animated:YES]; | ||
| 283 | -// | ||
| 284 | -// } else if ([model.type isEqualToString:@"subject"]) { | ||
| 285 | -// // SCIOSpecialViewController *vc = [[SCIOSpecialViewController alloc] initWithDictionary:_dic]; | ||
| 286 | -// // vc.title = @"国新专题"; | ||
| 287 | -// // vc.hidesBottomBarWhenPushed = YES; | ||
| 288 | -// | ||
| 289 | -// } else if ([model.type isEqualToString:@"LK"]) { | ||
| 290 | -// ArticleDetailViewController *vc = [[ArticleDetailViewController alloc] init]; | ||
| 291 | -// vc.model = model; | ||
| 292 | -// vc.hidesBottomBarWhenPushed = YES; | ||
| 293 | -// [self.navigationController pushViewController:vc animated:YES]; | ||
| 294 | -// | ||
| 295 | -// } | ||
| 296 | NSDictionary *_dic = [model toDictionary]; | 270 | NSDictionary *_dic = [model toDictionary]; |
| 297 | if ([@"program" isEqualToString:_dic[@"type"]]) { | 271 | if ([@"program" isEqualToString:_dic[@"type"]]) { |
| 298 | //视频 | 272 | //视频 |
CNLiveScioLive/Pages/Live/Controller/VideoPlayBackViewController.m
| @@ -222,23 +222,23 @@ | @@ -222,23 +222,23 @@ | ||
| 222 | } | 222 | } |
| 223 | backgroundView.bounces = NO; | 223 | backgroundView.bounces = NO; |
| 224 | [self.view addSubview:backgroundView]; | 224 | [self.view addSubview:backgroundView]; |
| 225 | - // | ||
| 226 | 225 | ||
| 227 | - WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc]init]; | ||
| 228 | - | ||
| 229 | - config.preferences = [WKPreferences new]; | ||
| 230 | - config.preferences.minimumFontSize = 20; | ||
| 231 | - | ||
| 232 | - config.preferences.javaScriptEnabled = YES; | ||
| 233 | - config.preferences.javaScriptCanOpenWindowsAutomatically = YES; | ||
| 234 | - config.userContentController = [[WKUserContentController alloc]init]; | ||
| 235 | - relatedWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 200) configuration:config]; | 226 | + NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);"; |
| 227 | + | ||
| 228 | + WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]; | ||
| 229 | + WKUserContentController *wkUController = [[WKUserContentController alloc] init]; | ||
| 230 | + [wkUController addUserScript:wkUScript]; | ||
| 231 | + | ||
| 232 | + WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init]; | ||
| 233 | + config.userContentController = wkUController; | ||
| 234 | + relatedWebView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:config]; | ||
| 236 | // relatedWebView = [[WKWebView alloc] initWithFrame:CGRectZero]; | 235 | // relatedWebView = [[WKWebView alloc] initWithFrame:CGRectZero]; |
| 237 | relatedWebView.scrollView.backgroundColor = [UIColor whiteColor]; | 236 | relatedWebView.scrollView.backgroundColor = [UIColor whiteColor]; |
| 238 | // relatedWebView.dataDetectorTypes = UIDataDetectorTypeNone; | 237 | // relatedWebView.dataDetectorTypes = UIDataDetectorTypeNone; |
| 239 | relatedWebView.backgroundColor = [UIColor whiteColor]; | 238 | relatedWebView.backgroundColor = [UIColor whiteColor]; |
| 240 | relatedWebView.scrollView.bounces = NO; | 239 | relatedWebView.scrollView.bounces = NO; |
| 241 | relatedWebView.navigationDelegate = self; | 240 | relatedWebView.navigationDelegate = self; |
| 241 | + relatedWebView.UIDelegate = self; | ||
| 242 | relatedWebView.opaque = NO; | 242 | relatedWebView.opaque = NO; |
| 243 | relatedWebView.tag = 1000; | 243 | relatedWebView.tag = 1000; |
| 244 | [backgroundView addSubview:relatedWebView]; | 244 | [backgroundView addSubview:relatedWebView]; |
| @@ -398,8 +398,7 @@ | @@ -398,8 +398,7 @@ | ||
| 398 | 398 | ||
| 399 | #pragma mark - WKNavigationDelegate | 399 | #pragma mark - WKNavigationDelegate |
| 400 | // 页面开始加载时调用 | 400 | // 页面开始加载时调用 |
| 401 | -- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler | ||
| 402 | -{ | 401 | +- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { |
| 403 | NSURL *requestURL = navigationAction.request.URL; | 402 | NSURL *requestURL = navigationAction.request.URL; |
| 404 | NSString *scheme = navigationAction.request.URL.scheme; | 403 | NSString *scheme = navigationAction.request.URL.scheme; |
| 405 | if (([scheme isEqualToString: @"http"] || [scheme isEqualToString:@"https"] || [scheme isEqualToString: @"mailto" ]) && (navigationAction.navigationType == WKNavigationTypeLinkActivated )) { | 404 | if (([scheme isEqualToString: @"http"] || [scheme isEqualToString:@"https"] || [scheme isEqualToString: @"mailto" ]) && (navigationAction.navigationType == WKNavigationTypeLinkActivated )) { |
| @@ -409,94 +408,104 @@ | @@ -409,94 +408,104 @@ | ||
| 409 | decisionHandler(WKNavigationActionPolicyAllow); | 408 | decisionHandler(WKNavigationActionPolicyAllow); |
| 410 | } | 409 | } |
| 411 | // 页面加载完成之后调用 | 410 | // 页面加载完成之后调用 |
| 412 | -- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation | ||
| 413 | -{ | 411 | +- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { |
| 414 | if (1000 == webView.tag) { | 412 | if (1000 == webView.tag) { |
| 415 | CGRect frame = relatedWebView.frame; | 413 | CGRect frame = relatedWebView.frame; |
| 416 | frame.size.width = MainScreenWidth; | 414 | frame.size.width = MainScreenWidth; |
| 417 | frame.size.height = 1; | 415 | frame.size.height = 1; |
| 418 | relatedWebView.frame = frame; | 416 | relatedWebView.frame = frame; |
| 419 | - descriptionHeight = relatedWebView.scrollView.contentSize.height; | ||
| 420 | - [relatedWebView setFrame:CGRectMake(0, 0, MainScreenWidth, descriptionHeight)]; | ||
| 421 | - lineImage1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, descriptionHeight, MainScreenWidth, 1)]; | ||
| 422 | - lineImage1.backgroundColor = Color_Line; | ||
| 423 | - [backgroundView addSubview:lineImage1]; | ||
| 424 | - | ||
| 425 | - upDownButton = [UIButton buttonWithType:UIButtonTypeCustom]; | ||
| 426 | - [upDownButton addTarget:self action:@selector(showGraphicLive:) forControlEvents:UIControlEventTouchUpInside]; | ||
| 427 | - [upDownButton setFrame:CGRectMake(0, descriptionHeight, MainScreenWidth, 40)]; | ||
| 428 | - [backgroundView addSubview:upDownButton]; | ||
| 429 | - | ||
| 430 | - UILabel *graphicLive = [[UILabel alloc] initWithFrame:CGRectMake(20, descriptionHeight, MainScreenWidth/2, 40)]; | ||
| 431 | - graphicLive.font = [UIFont systemFontOfSize:13]; | ||
| 432 | - graphicLive.backgroundColor = [UIColor clearColor]; | ||
| 433 | - graphicLive.textColor = HEXCOLOR(0x184085); | ||
| 434 | - [backgroundView addSubview:graphicLive]; | ||
| 435 | - graphicLive.text = @"发布会图文播报"; | ||
| 436 | - | ||
| 437 | - upDownImage = [[UIImageView alloc] initWithFrame:CGRectMake(MainScreenWidth - 31, descriptionHeight + 16, 13, 7)]; | ||
| 438 | - upDownImage.image = [UIImage imageNamed:@"cnlive_button_down"]; | ||
| 439 | - [backgroundView addSubview:upDownImage]; | ||
| 440 | - | ||
| 441 | - lineImage2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40 + descriptionHeight, MainScreenWidth, 1)]; | ||
| 442 | - lineImage2.backgroundColor = Color_Line; | ||
| 443 | - [backgroundView addSubview:lineImage2]; | 417 | +// descriptionHeight = relatedWebView.scrollView.contentSize.height; |
| 444 | 418 | ||
| 445 | - [backgroundView setContentSize:CGSizeMake(MainScreenWidth, 40 + descriptionHeight)]; | 419 | + [webView evaluateJavaScript:@"document.body.scrollHeight"completionHandler:^(id _Nullable result,NSError * _Nullable error){ |
| 420 | + NSLog(@"scrollHeight高度:%.2f",[result floatValue]); | ||
| 421 | + descriptionHeight = [result floatValue]; | ||
| 422 | + [relatedWebView setFrame:CGRectMake(0, 0, MainScreenWidth, descriptionHeight)]; | ||
| 423 | + lineImage1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, descriptionHeight, MainScreenWidth, 1)]; | ||
| 424 | + lineImage1.backgroundColor = Color_Line; | ||
| 425 | + [backgroundView addSubview:lineImage1]; | ||
| 446 | 426 | ||
| 447 | - WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc]init]; | ||
| 448 | - | ||
| 449 | - config.preferences = [WKPreferences new]; | ||
| 450 | - config.preferences.minimumFontSize = 12; | ||
| 451 | - | ||
| 452 | - config.preferences.javaScriptEnabled = YES; | ||
| 453 | - config.preferences.javaScriptCanOpenWindowsAutomatically = YES; | ||
| 454 | - config.userContentController = [[WKUserContentController alloc]init]; | ||
| 455 | - _webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:config]; | 427 | + upDownButton = [UIButton buttonWithType:UIButtonTypeCustom]; |
| 428 | + [upDownButton addTarget:self action:@selector(showGraphicLive:) forControlEvents:UIControlEventTouchUpInside]; | ||
| 429 | + [upDownButton setFrame:CGRectMake(0, descriptionHeight, MainScreenWidth, 40)]; | ||
| 430 | + [backgroundView addSubview:upDownButton]; | ||
| 431 | + | ||
| 432 | + UILabel *graphicLive = [[UILabel alloc] initWithFrame:CGRectMake(20, descriptionHeight, MainScreenWidth/2, 40)]; | ||
| 433 | + graphicLive.font = [UIFont systemFontOfSize:13]; | ||
| 434 | + graphicLive.backgroundColor = [UIColor clearColor]; | ||
| 435 | + graphicLive.textColor = HEXCOLOR(0x184085); | ||
| 436 | + [backgroundView addSubview:graphicLive]; | ||
| 437 | + graphicLive.text = @"发布会图文播报"; | ||
| 438 | + | ||
| 439 | + upDownImage = [[UIImageView alloc] initWithFrame:CGRectMake(MainScreenWidth - 31, descriptionHeight + 16, 13, 7)]; | ||
| 440 | + upDownImage.image = [UIImage imageNamed:@"cnlive_button_down"]; | ||
| 441 | + [backgroundView addSubview:upDownImage]; | ||
| 442 | + | ||
| 443 | + lineImage2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40 + descriptionHeight, MainScreenWidth, 1)]; | ||
| 444 | + lineImage2.backgroundColor = Color_Line; | ||
| 445 | + [backgroundView addSubview:lineImage2]; | ||
| 446 | + | ||
| 447 | + [backgroundView setContentSize:CGSizeMake(MainScreenWidth, 40 + descriptionHeight)]; | ||
| 448 | + | ||
| 449 | + NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);"; | ||
| 456 | 450 | ||
| 457 | -// _webView = [[WKWebView alloc] initWithFrame:CGRectZero]; | ||
| 458 | - _webView.scrollView.backgroundColor = [UIColor clearColor]; | ||
| 459 | -// _webView.dataDetectorTypes = UIDataDetectorTypeNone; | ||
| 460 | - _webView.backgroundColor = [UIColor clearColor]; | ||
| 461 | - _webView.scrollView.bounces = NO; | ||
| 462 | - _webView.UIDelegate = self; | ||
| 463 | - | ||
| 464 | - _webView.opaque = NO; | ||
| 465 | - _webView.tag = 2000; | ||
| 466 | - | ||
| 467 | - [backgroundView addSubview:_webView]; | 451 | + WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]; |
| 452 | + WKUserContentController *wkUController = [[WKUserContentController alloc] init]; | ||
| 453 | + [wkUController addUserScript:wkUScript]; | ||
| 454 | + | ||
| 455 | + WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init]; | ||
| 456 | + config.userContentController = wkUController; | ||
| 457 | + | ||
| 458 | + _webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:config]; | ||
| 459 | + // _webView = [[WKWebView alloc] initWithFrame:CGRectZero]; | ||
| 460 | + _webView.scrollView.backgroundColor = [UIColor clearColor]; | ||
| 461 | + // _webView.dataDetectorTypes = UIDataDetectorTypeNone; | ||
| 462 | + _webView.backgroundColor = [UIColor clearColor]; | ||
| 463 | + _webView.scrollView.bounces = NO; | ||
| 464 | + _webView.UIDelegate = self; | ||
| 465 | + _webView.navigationDelegate = self; | ||
| 466 | + | ||
| 467 | + _webView.opaque = NO; | ||
| 468 | + _webView.tag = 2000; | ||
| 469 | + | ||
| 470 | + [backgroundView addSubview:_webView]; | ||
| 471 | + | ||
| 472 | + }]; | ||
| 468 | [self loadRelatedInformation]; | 473 | [self loadRelatedInformation]; |
| 469 | [self loadData]; | 474 | [self loadData]; |
| 470 | - } | ||
| 471 | - else if (2000 == webView.tag) { | ||
| 472 | - CGFloat width = MainScreenWidth - 20; | ||
| 473 | - NSString *string = [NSString stringWithFormat: | ||
| 474 | - @"var script = document.createElement('script');" | ||
| 475 | - "script.type = 'text/javascript';" | ||
| 476 | - "script.text = \"function ResizeImages() { " | ||
| 477 | - "var myimg,oldwidth;" | ||
| 478 | - "var maxwidth=%f;" //缩放系数 | ||
| 479 | - "for(i=0;i <document.images.length;i++){" | ||
| 480 | - "myimg = document.images[i];" | ||
| 481 | - "if(myimg.width > maxwidth){" | ||
| 482 | - "oldwidth = myimg.width;" | ||
| 483 | - "myimg.width = maxwidth;" | ||
| 484 | - "myimg.height = myimg.height * (maxwidth/oldwidth);" | ||
| 485 | - "}" | ||
| 486 | - "}" | ||
| 487 | - "}\";" | ||
| 488 | - "document.getElementsByTagName('head')[0].appendChild(script);",width]; | 475 | + |
| 476 | + } else if (2000 == webView.tag) { | ||
| 477 | + CGFloat width = MainScreenWidth - 20; | ||
| 478 | + NSString *string = [NSString stringWithFormat: | ||
| 479 | + @"var script = document.createElement('script');" | ||
| 480 | + "script.type = 'text/javascript';" | ||
| 481 | + "script.text = \"function ResizeImages() { " | ||
| 482 | + "var myimg,oldwidth;" | ||
| 483 | + "var maxwidth=%f;" //缩放系数 | ||
| 484 | + "for(i=0;i <document.images.length;i++){" | ||
| 485 | + "myimg = document.images[i];" | ||
| 486 | + "if(myimg.width > maxwidth){" | ||
| 487 | + "oldwidth = myimg.width;" | ||
| 488 | + "myimg.width = maxwidth;" | ||
| 489 | + "myimg.height = myimg.height * (maxwidth/oldwidth);" | ||
| 490 | + "}" | ||
| 491 | + "}" | ||
| 492 | + "}\";" | ||
| 493 | + "document.getElementsByTagName('head')[0].appendChild(script);",width]; | ||
| 489 | // [webView stringByEvaluatingJavaScriptFromString:string]; | 494 | // [webView stringByEvaluatingJavaScriptFromString:string]; |
| 490 | // [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"]; | 495 | // [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"]; |
| 491 | - [webView evaluateJavaScript:string completionHandler:nil]; | ||
| 492 | - [webView evaluateJavaScript:@"ResizeImages();" completionHandler:nil]; | ||
| 493 | - | ||
| 494 | - CGRect frame = _webView.frame; | ||
| 495 | - frame.size.width = MainScreenWidth; | ||
| 496 | - frame.size.height = 1; | ||
| 497 | - _webView.frame = frame; | ||
| 498 | - graphicLiveHeight = _webView.scrollView.contentSize.height; | ||
| 499 | - | 496 | + [webView evaluateJavaScript:string completionHandler:nil]; |
| 497 | + [webView evaluateJavaScript:@"ResizeImages();" completionHandler:nil]; | ||
| 498 | + | ||
| 499 | + CGRect frame = _webView.frame; | ||
| 500 | + frame.size.width = MainScreenWidth; | ||
| 501 | + frame.size.height = 1; | ||
| 502 | + _webView.frame = frame; | ||
| 503 | +// graphicLiveHeight = _webView.scrollView.contentSize.height; | ||
| 504 | + | ||
| 505 | + CGFloat contentHeight = webView.scrollView.contentSize.height; | ||
| 506 | + [webView evaluateJavaScript:@"document.body.scrollHeight"completionHandler:^(id _Nullable result,NSError * _Nullable error){ | ||
| 507 | + NSLog(@"scrollHeight高度:%.2f",[result floatValue]); | ||
| 508 | + graphicLiveHeight = [result floatValue]; | ||
| 500 | NSLog(@"%@",NSStringFromCGRect(_webView.frame)); | 509 | NSLog(@"%@",NSStringFromCGRect(_webView.frame)); |
| 501 | NSLog(@"%@",NSStringFromCGSize(_webView.scrollView.contentSize)); | 510 | NSLog(@"%@",NSStringFromCGSize(_webView.scrollView.contentSize)); |
| 502 | if (0 == [heightArr[fontIndex] floatValue]) { | 511 | if (0 == [heightArr[fontIndex] floatValue]) { |
| @@ -512,7 +521,9 @@ | @@ -512,7 +521,9 @@ | ||
| 512 | [self.tableView setFrame:frame]; | 521 | [self.tableView setFrame:frame]; |
| 513 | _webView.hidden = NO; | 522 | _webView.hidden = NO; |
| 514 | } | 523 | } |
| 515 | - } | 524 | + }]; |
| 525 | + | ||
| 526 | + } | ||
| 516 | } | 527 | } |
| 517 | 528 | ||
| 518 | - (void)shareButtonCNLivePlayerController:(CNLivePlayerController *)view{ | 529 | - (void)shareButtonCNLivePlayerController:(CNLivePlayerController *)view{ |
| @@ -668,4 +679,5 @@ | @@ -668,4 +679,5 @@ | ||
| 668 | - (UIInterfaceOrientationMask)supportedInterfaceOrientations { | 679 | - (UIInterfaceOrientationMask)supportedInterfaceOrientations { |
| 669 | return UIInterfaceOrientationMaskAllButUpsideDown; | 680 | return UIInterfaceOrientationMaskAllButUpsideDown; |
| 670 | } | 681 | } |
| 682 | + | ||
| 671 | @end | 683 | @end |