// // FaDetaiH5ViewController.m // jitao // // Created by 罗云飞 on 2018/9/7. // Copyright © 2018年 罗云飞. All rights reserved. // #import "FaDetaiH5ViewController.h" #import "TGWebProgressLayer.h" #import #import "NewKeFuViewController.h" @interface FaDetaiH5ViewController (){ UIWebView *_myWebView; } @property (nonatomic, strong)WKWebView *mainWebView; @property (nonatomic, strong)TGWebProgressLayer *webProgressLayer; @property (strong ,nonatomic) UIButton * registerAccount; @end @implementation FaDetaiH5ViewController - (void)viewDidLoad { [super viewDidLoad]; [self setNavTitle:[NSString stringWithFormat:@"%@详情",self.type]]; NSString *ind; if ([self.type isEqualToString:@"政策"]) { ind = @"0"; }else{ ind = @"1"; } NSString *htmlPath = [NSString stringWithFormat:@"%@/1.0/template/find/findDetails.html?id=%@&&ind=%@",HTML5_URL,self.ID,ind]; _myWebView = [[UIWebView alloc] init]; // [_myWebView.scrollView setDelegate:self]; [_myWebView setDelegate:self]; _myWebView.scrollView.tag = 112; _myWebView.backgroundColor = [UIColor clearColor]; //自动对页面进行缩放以适应屏幕 [_myWebView setScalesPageToFit:YES]; if (htmlPath) { NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:htmlPath] cachePolicy:NSURLRequestReloadRevalidatingCacheData timeoutInterval:60*60*24*1]; [_myWebView loadRequest:request]; } [self.view addSubview:_myWebView]; // NSURL *baseURL = [NSURL fileURLWithPath:htmlPath]; // [webView loadHTMLString:htmlPath baseURL:baseURL]; _myWebView.sd_layout .rightSpaceToView(self.view,0) .topSpaceToView(self.view,NavHeader) .heightIs(SCREEN_HEIGHT-NavHeader) .widthIs(SCREEN_WIDTH); // [self loadsView]; // Do any additional setup after loading the view. } - (UIButton *)registerAccount { if (!_registerAccount) { _registerAccount = [UIButton buttonWithType:UIButtonTypeCustom]; // [_registerAccount setTitle:@"" forState:UIControlStateNormal]; [_registerAccount setTitleColor:[UIColor colorWithString:@"#9A9A9A"] forState:UIControlStateNormal]; [_registerAccount setBackgroundColor:[UIColor clearColor]]; [_registerAccount setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight]; [_registerAccount.titleLabel setFont:[UIFont systemFontOfSize:fitScreenWidth(14)]]; [_registerAccount addTarget:self action:@selector(touchRegister:) forControlEvents:UIControlEventTouchUpInside]; // [_registerAccount setupAutoSizeWithHorizontalPadding:5 buttonHeight:44]; [_registerAccount setImage:NewImageNamed(@"gd") forState:UIControlStateNormal]; } return _registerAccount; } #pragma mark - UI初始化 - (void)loadsView { // [self.navgationBar addSubview:self.registerAccount]; // _registerAccount.sd_layout // .widthIs(30) // .rightSpaceToView(self.navgationBar, 10) // .heightIs(44) // .topSpaceToView(self.navgationBar, 18); self.mainWebView = [WKWebView new]; self.mainWebView.navigationDelegate =self; [self.view addSubview:self.mainWebView]; self.mainWebView.sd_layout .rightSpaceToView(self.view,0) .topSpaceToView(self.view,NavHeader) .heightIs(SCREEN_HEIGHT-NavHeader) .widthIs(SCREEN_WIDTH); [self loadContent]; self.webProgressLayer = [[TGWebProgressLayer alloc] init]; self.webProgressLayer.frame = CGRectMake(0, NavHeader-2, WIDTH, 2); self.webProgressLayer.strokeColor = NewRGBColor(30, 144, 255, 1).CGColor; [self.view.layer addSublayer:self.webProgressLayer]; UIView *view = [UIView new]; view.backgroundColor = NewWhiteColor; // [self.view addSubview:view]; view.sd_layout .leftEqualToView(self.view) .widthIs(SCREEN_WIDTH) .heightIs(45) .bottomEqualToView(self.view); UIButton *button = [UIButton new]; [button setTitle:@"立即咨询" forState:UIControlStateNormal]; [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal]; button.titleLabel.font = NewFont(16); ViewBorderRadius(button, 5, 1, NewLineGrayColor); NewTouchUpInside(button, buttonclick:); [view addSubview:button]; button.sd_layout .leftSpaceToView(view, 15) .rightSpaceToView(view, 15) .heightIs(35) .topSpaceToView(view, 5); } - (void)buttonclick:(UIButton *)sender { NewKeFuViewController *vc = [NewKeFuViewController new]; NewPushViewController(vc); } #pragma mark - 加载Web数据 -(void)loadContent { // int x = arc4random() % 10000000; // http://muat.jishutao.com/1.0/template/find/findDetails.html?id=243763876884570112&&ind=0 // http://muat.jishutao.com/1.0/template/project/projectDetail.html?id=308087e5-b1d0-48fa-b1d1-d9b86b9062be NSString *ind; if ([self.type isEqualToString:@"政策"]) { ind = @"0"; }else{ ind = @"1"; } NSString *url = [NSString stringWithFormat:@"%@/1.0/template/find/findDetails.html?id=%@&&ind=%@",HTML5_URL,self.ID,ind]; NSURL *urlString = [NSURL URLWithString:url]; // NSURLRequest *request = [NSURLRequest requestWithURL:urlString]; //加载请求的时候忽略缓存 NSURLRequest *request = [NSURLRequest requestWithURL:urlString cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:5.0]; [self.mainWebView loadRequest:request]; } #pragma mark - WKWebViewDelegate - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation { [self.webProgressLayer tg_startLoad]; } - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { [self.webProgressLayer tg_finishedLoadWithError:nil]; } - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error { [self.webProgressLayer tg_finishedLoadWithError:error]; } - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { NSString *hostname = navigationAction.request.URL.host.lowercaseString; if (navigationAction.navigationType == WKNavigationTypeLinkActivated && ![hostname containsString:HTML5_URL]) { decisionHandler(WKNavigationActionPolicyCancel); }else { decisionHandler(WKNavigationActionPolicyAllow); } } //UIWebView的代理方法 - (void)webViewDidFinishLoad:(UIWebView *)webView { //具体去除广告的操作 //查看更详细的操作进入:http://jwdev.cn/2015/09/28/use-javascript-to-delete-web-element/ [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('m-container')[0].style.display = 'none'"]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end