记录webView的浏览位置

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
    
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    
    if ([webView.URL isEqual:self.url]) {
        CGFloat offsetY = 0;
        offsetY = [[NSUserDefaults standardUserDefaults] floatForKey:@"webViewOffsetY"];
        if (offsetY) {
            [webView.scrollView setContentOffset:CGPointMake(0, offsetY) animated:NO];
        }
    }
}


- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    CGFloat offsetY = scrollView.contentOffset.y;
    [[NSUserDefaults standardUserDefaults] setFloat:offsetY forKey:@"webViewOffsetY"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

你可能感兴趣的:(记录webView的浏览位置)