MyWebViewVC.m 2.1 KB

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