計(jì)算wkWebView進(jìn)度條
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == self.webview && [keyPath isEqualToString:@"estimatedProgress"]) {
CGFloat newprogress = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
if (newprogress == 1) {
self.progressView.hidden = YES;
[self.progressView setProgress:0 animated:NO];
}else {
self.progressView.hidden = NO;
[self.progressView setProgress:newprogress animated:YES];
}
}
}
關(guān)于使用kvo監(jiān)聽(tīng)模式 change 取值問(wèn)題?
使用CGRect newRect = [[change objectForKey:NSKeyValueChangeNewKey] CGRectValue];
boolValue跷叉、integerValue蛔溃、intValue、CGPointValue等等 取到你想要的數(shù)據(jù)
不能使用valueForKey取值?
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void *)context{
if ([keyPath isEqualToString:@"frame"]) {
CGRect newRect = [[change objectForKey:NSKeyValueChangeNewKey] CGRectValue];
if (newRect.size.width == ScreenW) {
//擴(kuò)散到整個(gè)屏幕
}
}
}