NewWebController.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // NewWebController.m
  3. // JianYuIOS
  4. //
  5. // Created by lixianglan on 2018/2/1.
  6. // Copyright © 2018年 lixianglan. All rights reserved.
  7. //
  8. #import "NewWebController.h"
  9. @interface NewWebController ()<UIWebViewDelegate>
  10. @property (weak, nonatomic) IBOutlet UIWebView *webView;
  11. @property (weak, nonatomic) IBOutlet UIButton *backBtn;
  12. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topC;
  13. @property(nonatomic, strong)LXProgressView *progressView;
  14. @property (weak, nonatomic) IBOutlet UIView *topView;
  15. @property (weak, nonatomic) IBOutlet UILabel *titleLbl;
  16. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewH;
  17. @end
  18. @implementation NewWebController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view from its nib.
  22. // if ([[UIDevice currentDevice].systemVersion floatValue] >= 11.0) {
  23. // self.topC.constant = -20;
  24. // [self.webView updateConstraints];
  25. // }
  26. if (IphonexAboveScreen) {
  27. self.topC.constant = 44;
  28. [self.view updateConstraints];
  29. }
  30. NSLog(@"%@",self.titleShow);
  31. if (self.titleShow) {
  32. self.backBtn.hidden = YES;
  33. self.titleLbl.text = self.titleShow;
  34. if([self.titleShow isEqualToString:@"-1"]) {
  35. self.topC.constant = -20;
  36. [self.webView updateConstraints];
  37. self.topViewH.constant = 0;
  38. self.topView.hidden = YES;
  39. [self.view updateConstraints];
  40. }
  41. }else{
  42. self.topC.constant = -20;
  43. [self.webView updateConstraints];
  44. self.topViewH.constant = 0;
  45. self.topView.hidden = YES;
  46. [self.view updateConstraints];
  47. }
  48. self.webView.scrollView.bounces = NO;
  49. self.webView.delegate = self;
  50. self.webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
  51. self.webView.scalesPageToFit=YES;
  52. self.webView.multipleTouchEnabled=YES;
  53. self.webView.userInteractionEnabled=YES;
  54. // [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
  55. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
  56. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissSelf) name:@"kNewWebControllerDismiss" object:nil];
  57. }
  58. -(void)dismissSelf{
  59. kMainQueue(^{
  60. [self dismissViewControllerAnimated:NO completion:nil];
  61. });
  62. }
  63. #pragma mark webView代理方法
  64. -(void)webViewDidFinishLoad:(UIWebView *)webView{
  65. // [[LXViewControllerManager shareViewControllerManager] hideHud];
  66. [self removeProgresView];
  67. // Disable user selection
  68. [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
  69. // Disable callout
  70. [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
  71. }
  72. -(void)webViewDidStartLoad:(UIWebView *)webView{
  73. if (!self.titleShow) {
  74. [self addProgressView];
  75. }
  76. }
  77. // 显示加载进度条
  78. -(void)addProgressView{
  79. if (self.progressView) {
  80. [self.progressView removeFromSuperview];
  81. self.progressView = nil;
  82. }
  83. self.progressView = [[LXProgressView alloc] init];
  84. self.progressView.frame = CGRectMake(0, CGRectGetMinY(self.webView.frame), kCurrentDeviceWidth, 2);
  85. [self.view addSubview:self.progressView];
  86. }
  87. // 移除加载进度条
  88. -(void)removeProgresView{
  89. self.progressView.progress = .99;
  90. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  91. if (self.progressView) {
  92. [self.progressView removeFromSuperview];
  93. self.progressView = nil;
  94. }
  95. });
  96. }
  97. - (IBAction)backBtnAction:(id)sender {
  98. if (self.webView.canGoBack) {// web能退 就后退
  99. [self.webView goBack];
  100. }else{// 跳回上级页面
  101. [self dismissViewControllerAnimated:NO completion:nil];
  102. }
  103. }
  104. - (void)didReceiveMemoryWarning {
  105. [super didReceiveMemoryWarning];
  106. // Dispose of any resources that can be recreated.
  107. NSURLCache * cache = [NSURLCache sharedURLCache];
  108. [cache removeAllCachedResponses];
  109. [cache setDiskCapacity:0];
  110. [cache setMemoryCapacity:0];
  111. }
  112. /*
  113. #pragma mark - Navigation
  114. // In a storyboard-based application, you will often want to do a little preparation before navigation
  115. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  116. // Get the new view controller using [segue destinationViewController].
  117. // Pass the selected object to the new view controller.
  118. }
  119. */
  120. @end