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
相关文章推荐
- 七天学会ASP.NET MVC(七)――创建单页应用
- 黑马程序员-反射
- 熟悉开发板
- Android数据库SQLite的使用
- leetCode #225 Implement Stack using Queues
- 操作系统知识点
- 七天学会ASP.NET MVC(七)——创建单页应用
- 堆排序算法
- 模块间引用的编译错误
- 102 Binary Tree Level Order Traversal
- python http post json
- spring3.0 使用@value 加载配置文件property
- python-装饰器学习示例
- HDU 5045 Contest
- Export aborted because fatal Lin error were founds. These are listed in the problems view. Either fi
- js控制元素显示在屏幕固定位置及监听屏幕高度变化的方法
- C++输出精度控制
- 带输出参数的存储过程的定义,以及在aso.net中调用
- java中比较两个double类型的数据大小
- HTML5 3D翻书效果(双面效应)