KVC

#import "fileutil.h"
#import "PrivacyView.h"
#import "AppConstant.h"
@import WebKit;
@interface PrivacyView()<WKNavigationDelegate>{

    NSString *website;
    
}

@property (strong, nonatomic) IBOutlet UIWebView *webView2;
@property (nonatomic, strong) WKWebView *webView;
@property (nonatomic, strong) UIProgressView *progress;
@property (nonatomic, strong) UIActivityIndicatorView *indicator;


@end

@implementation PrivacyView

@synthesize webView;

- (void)viewDidLoad

{
	[super viewDidLoad];
   
    switch (self.shiftId) {
        case 0:
            self.title = @"用户中心";
            website = WEB_URL_ZIXUN;
        break;
            
        default:
            self.title = TAB_ITEM_NAME3;
            website = WEB_URL_YONGHUZHONGXIN;
            break;
    }
    self.webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
    self.webView.allowsBackForwardNavigationGestures = YES;
    self.webView.navigationDelegate = self;
    [self.view addSubview:self.webView];

    [webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:nil];
    //Progress
    /*
    _progress = [[UIProgressView alloc]init];
    [self.view insertSubview:webView belowSubview:_progress];
    [_progress addObserver:self forKeyPath:@"progress" options:NSKeyValueObservingOptionNew context:nil];
     */
    //indicator
    _indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    NSLog(@"[%f,%f][157143]",self.view.frame.size.width,self.view.frame.size.height);
    _indicator.frame = CGRectMake(self.view.frame.size.width/2-20, 250, 100, 100);
    [self.view addSubview:_indicator];
   
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    
    if([keyPath isEqual:@"title"]){
        NSLog(@"%@[157101]",webView.title);
        if (!self.shiftId) {
            self.title = webView.title;
        }
            }
    
    if([keyPath isEqual:@"progress"]){
        _progress.hidden = webView.estimatedProgress == 1;
        [_progress setProgress:webView.estimatedProgress animated:true];
   
   }
   }

- (void)viewWillAppear:(BOOL)animated

{
	[super viewWillAppear:animated];
   
	webView.frame = self.view.bounds;
//	NSString *website = @"http://192.168.16.52/eduapp/inst/home/index";
//    NSString *website = @"http://192.168.16.52/eduapp/tch/";//[9:04,2015-7-14]
//    NSString *website = @"http://192.168.16.52/eduapp/home/news";//[15:45,2015-7-14]
//    NSString *website = @"http://192.168.16.52/eduapp/stu/home/index";//[16:44,2015-7-14]
//    NSString *website = @"http://localhost:2000/index.html";
//	[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:Applications(@"privacy.html")]]];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:website]]];
}
- (void)viewWillDisappear:(BOOL)animated{
   
    if (webView) {
        @try {
            [webView removeObserver:self forKeyPath:@"title"];
            [webView removeObserver:self forKeyPath:@"progress"];
        }
        @catch (NSException * __unused exception) {
            NSLog(@"%@ [157141]",exception);
        }
       
    }
    
}
- (void)didReceiveMemoryWarning
{
 
}
#pragma mark - WKNavigationDelegate
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
    NSLog(@"didStartProvisionalNavigation");
    [_indicator startAnimating];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = true;
    
}
- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
    NSLog(@"didCommitNavigation");
}
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
    NSLog(@"didFinishNavigation");
    [_indicator stopAnimating];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = false;
}
@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值