123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- //
- // NewWebController.m
- // JianYuIOS
- //
- // Created by lixianglan on 2018/2/1.
- // Copyright © 2018年 lixianglan. All rights reserved.
- //
- #import "NewWebController.h"
- @interface NewWebController ()<UIWebViewDelegate>
- @property (weak, nonatomic) IBOutlet UIWebView *webView;
- @property (weak, nonatomic) IBOutlet UIButton *backBtn;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topC;
- @property(nonatomic, strong)LXProgressView *progressView;
- @property (weak, nonatomic) IBOutlet UIView *topView;
- @property (weak, nonatomic) IBOutlet UILabel *titleLbl;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewH;
- @end
- @implementation NewWebController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
- // if ([[UIDevice currentDevice].systemVersion floatValue] >= 11.0) {
- // self.topC.constant = -20;
- // [self.webView updateConstraints];
- // }
- if (IphonexAboveScreen) {
- self.topC.constant = 44;
- [self.view updateConstraints];
- }
-
- NSLog(@"%@",self.titleShow);
- if (self.titleShow) {
- self.backBtn.hidden = YES;
- self.titleLbl.text = self.titleShow;
-
- if([self.titleShow isEqualToString:@"-1"]) {
- self.topC.constant = -20;
- [self.webView updateConstraints];
- self.topViewH.constant = 0;
- self.topView.hidden = YES;
- [self.view updateConstraints];
- }
- }else{
-
- self.topC.constant = -20;
- [self.webView updateConstraints];
-
- self.topViewH.constant = 0;
- self.topView.hidden = YES;
- [self.view updateConstraints];
- }
-
- self.webView.scrollView.bounces = NO;
- self.webView.delegate = self;
-
- self.webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
- self.webView.scalesPageToFit=YES;
- self.webView.multipleTouchEnabled=YES;
- self.webView.userInteractionEnabled=YES;
-
- // [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
- [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissSelf) name:@"kNewWebControllerDismiss" object:nil];
- }
- -(void)dismissSelf{
- kMainQueue(^{
- [self dismissViewControllerAnimated:NO completion:nil];
- });
- }
- #pragma mark webView代理方法
- -(void)webViewDidFinishLoad:(UIWebView *)webView{
- // [[LXViewControllerManager shareViewControllerManager] hideHud];
- [self removeProgresView];
- // Disable user selection
- [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
- // Disable callout
- [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
- }
- -(void)webViewDidStartLoad:(UIWebView *)webView{
- if (!self.titleShow) {
- [self addProgressView];
- }
- }
- // 显示加载进度条
- -(void)addProgressView{
- if (self.progressView) {
- [self.progressView removeFromSuperview];
- self.progressView = nil;
- }
- self.progressView = [[LXProgressView alloc] init];
- self.progressView.frame = CGRectMake(0, CGRectGetMinY(self.webView.frame), kCurrentDeviceWidth, 2);
- [self.view addSubview:self.progressView];
- }
- // 移除加载进度条
- -(void)removeProgresView{
- self.progressView.progress = .99;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- if (self.progressView) {
- [self.progressView removeFromSuperview];
- self.progressView = nil;
- }
- });
- }
- - (IBAction)backBtnAction:(id)sender {
- if (self.webView.canGoBack) {// web能退 就后退
- [self.webView goBack];
- }else{// 跳回上级页面
- [self dismissViewControllerAnimated:NO completion:nil];
- }
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- NSURLCache * cache = [NSURLCache sharedURLCache];
- [cache removeAllCachedResponses];
- [cache setDiskCapacity:0];
- [cache setMemoryCapacity:0];
- }
- /*
- #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
|