口袋优选

KBFindBookWebViewController.m 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // KBFindBookWebViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by xiaoxi on 2018/2/1.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBFindBookWebViewController.h"
  9. #import "KBFindRequestViewModel.h"
  10. #import "WebviewProgressLine.h"
  11. @interface KBFindBookWebViewController () <UIWebViewDelegate>
  12. /** 加载进度条 */
  13. @property (nonatomic,strong) WebviewProgressLine *progressLine;
  14. @end
  15. @implementation KBFindBookWebViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. [self initHUD];
  19. [self initNavBar];
  20. [self requestGuideBook];
  21. }
  22. - (void)viewWillDisappear:(BOOL)animated {
  23. [super viewWillDisappear:animated];
  24. [SVProgressHUD dismiss];
  25. }
  26. - (void)didReceiveMemoryWarning {
  27. [super didReceiveMemoryWarning];
  28. }
  29. - (void)initNavBar {
  30. [self.navigationBar setBackButtonWithTarget:self selector:@selector(backAction)];
  31. [self.navigationBar setShowNavigationBarBottomLine:YES];
  32. }
  33. - (void)backAction {
  34. [self.navigationController popViewControllerAnimated:YES];
  35. }
  36. - (void)initSubviewsWith:(NSString *)url {
  37. UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, NavBarHeight, kScreenWidth, kScreenHeight-NavBarHeight)];
  38. webView.backgroundColor = [UIColor clearColor];
  39. webView.scalesPageToFit = YES;
  40. webView.delegate = self;
  41. [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  42. [self.view addSubview:webView];
  43. self.progressLine = [[WebviewProgressLine alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, 3)];
  44. self.progressLine.lineColor = [UIColor YHColorWithHex:0xCC0E0E];
  45. [self.view addSubview:self.progressLine];
  46. }
  47. #pragma mark - HUD
  48. - (void)initHUD {
  49. [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
  50. [SVProgressHUD setForegroundColor:[UIColor YHColorWithHex:0xff2420]];
  51. [SVProgressHUD setBackgroundColor:[UIColor YHColorWithHex:0xf5f4f4]];
  52. }
  53. #pragma mark - request
  54. - (void)requestGuideBook {
  55. [SVProgressHUD show];
  56. // [KBFindRequestViewModel requestGuideBookSuccess:^(NSString *url) {
  57. // if (url.length > 0) {
  58. // [self initSubviewsWith:url];
  59. // }
  60. // } failure:^(NSError *error) {
  61. // [SVProgressHUD dismiss];
  62. // }];
  63. NSString *url = [NSString stringWithFormat:@"%@/api/v2/homeact/guideBook",BaseURL];
  64. [KBHttp get:url params:nil success:^(id json) {
  65. NSString *url;
  66. if (self.isGetMontyPage) {
  67. url = json[@"getMoneyUrl"];
  68. }else {
  69. url = json[@"url"];
  70. }
  71. [self initSubviewsWith:url];
  72. } failure:^(NSError *error) {
  73. [SVProgressHUD dismiss];
  74. }];
  75. }
  76. #pragma mark - webView
  77. - (void)webViewDidStartLoad:(UIWebView *)webView {
  78. [SVProgressHUD dismiss];
  79. [self.progressLine startLoadingAnimation];
  80. }
  81. - (void)webViewDidFinishLoad:(UIWebView *)webView {
  82. [SVProgressHUD dismiss];
  83. [self.navigationBar setNavTitle:[webView stringByEvaluatingJavaScriptFromString:@"document.title"]];
  84. [self.progressLine endLoadingAnimation];
  85. }
  86. - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
  87. [SVProgressHUD dismiss];
  88. [self.progressLine endLoadingAnimation];
  89. }
  90. @end