123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //
- // KBFindBookWebViewController.m
- // YouHuiProject
- //
- // Created by xiaoxi on 2018/2/1.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBFindBookWebViewController.h"
- #import "KBFindRequestViewModel.h"
- #import "WebviewProgressLine.h"
- @interface KBFindBookWebViewController () <UIWebViewDelegate>
- /** 加载进度条 */
- @property (nonatomic,strong) WebviewProgressLine *progressLine;
- @end
- @implementation KBFindBookWebViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self initHUD];
- [self initNavBar];
- [self requestGuideBook];
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [SVProgressHUD dismiss];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- - (void)initNavBar {
- [self.navigationBar setBackButtonWithTarget:self selector:@selector(backAction)];
- [self.navigationBar setShowNavigationBarBottomLine:YES];
- }
- - (void)backAction {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)initSubviewsWith:(NSString *)url {
- UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, NavBarHeight, kScreenWidth, kScreenHeight-NavBarHeight)];
- webView.backgroundColor = [UIColor clearColor];
- webView.scalesPageToFit = YES;
- webView.delegate = self;
- [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
- [self.view addSubview:webView];
- self.progressLine = [[WebviewProgressLine alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, 3)];
- self.progressLine.lineColor = [UIColor YHColorWithHex:0xCC0E0E];
- [self.view addSubview:self.progressLine];
- }
- #pragma mark - HUD
- - (void)initHUD {
- [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
- [SVProgressHUD setForegroundColor:[UIColor YHColorWithHex:0xff2420]];
- [SVProgressHUD setBackgroundColor:[UIColor YHColorWithHex:0xf5f4f4]];
- }
- #pragma mark - request
- - (void)requestGuideBook {
- [SVProgressHUD show];
-
- // [KBFindRequestViewModel requestGuideBookSuccess:^(NSString *url) {
- // if (url.length > 0) {
- // [self initSubviewsWith:url];
- // }
- // } failure:^(NSError *error) {
- // [SVProgressHUD dismiss];
- // }];
-
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/homeact/guideBook",BaseURL];
- [KBHttp get:url params:nil success:^(id json) {
-
- NSString *url;
- if (self.isGetMontyPage) {
- url = json[@"getMoneyUrl"];
- }else {
- url = json[@"url"];
- }
-
- [self initSubviewsWith:url];
-
- } failure:^(NSError *error) {
- [SVProgressHUD dismiss];
- }];
- }
- #pragma mark - webView
- - (void)webViewDidStartLoad:(UIWebView *)webView {
- [SVProgressHUD dismiss];
- [self.progressLine startLoadingAnimation];
- }
- - (void)webViewDidFinishLoad:(UIWebView *)webView {
- [SVProgressHUD dismiss];
- [self.navigationBar setNavTitle:[webView stringByEvaluatingJavaScriptFromString:@"document.title"]];
- [self.progressLine endLoadingAnimation];
- }
- - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
- [SVProgressHUD dismiss];
- [self.progressLine endLoadingAnimation];
- }
- @end
|