MyWebViewVC.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // MyWebViewVC.m
  3. // jiaPei
  4. //
  5. // Created by EchoShacolee on 2018/9/5.
  6. // Copyright © 2018年 JCZ. All rights reserved.
  7. //
  8. #import "MyWebViewVC.h"
  9. #import <WebKit/WebKit.h>
  10. @interface MyWebViewVC ()<WKNavigationDelegate>
  11. @property(nonatomic,strong)WKWebView *webView;
  12. @end
  13. @implementation MyWebViewVC
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. [self.view addSubview:self.webView];
  17. //返回按钮
  18. UIImage *backImg = [[UIImage imageNamed:@"scanBack"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  19. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithImage:backImg style:UIBarButtonItemStylePlain target:self action:@selector(goBack)];
  20. self.navigationItem.leftBarButtonItem = leftItem;
  21. //开始加载
  22. if (!_urlString || _urlString.length == 0) {
  23. return;
  24. }
  25. if (![Util connectedToNetWork]) {
  26. showMsgUnconnect();
  27. return;
  28. }
  29. [MBProgressHUD showLoadToView:self.view];
  30. NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:_urlString]];
  31. [self.webView loadRequest:request];
  32. }
  33. -(void)viewWillAppear:(BOOL)animated{
  34. [super viewWillAppear:animated];
  35. self.tabBarController.tabBar.hidden = YES;
  36. }
  37. -(void)goBack
  38. {
  39. [self.navigationController popViewControllerAnimated:YES];
  40. }
  41. -(WKWebView *)webView{
  42. if (!_webView) {
  43. WKWebView *view = [[WKWebView alloc] initWithFrame:kFrame];
  44. view.navigationDelegate = self;
  45. _webView = view;
  46. }
  47. return _webView;
  48. }
  49. #pragma mark -
  50. // 页面加载失败时调用
  51. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error{
  52. [MBProgressHUD hideHUDForView:self.view];
  53. }
  54. // 页面加载完毕时调用
  55. - (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
  56. [MBProgressHUD hideHUDForView:self.view];
  57. }
  58. - (void)didReceiveMemoryWarning {
  59. [super didReceiveMemoryWarning];
  60. // Dispose of any resources that can be recreated.
  61. }
  62. @end