您的位置:首页 > 其它

KVC

2015-08-11 12:16 423 查看
#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: