From ba0f9d5a8ae79c81925a4342e320c663aee75bc5 Mon Sep 17 00:00:00 2001 From: devedbox Date: Mon, 15 May 2017 11:54:25 +0800 Subject: [PATCH] Added title obverser. --- .../AXWebViewController/AXWebViewController.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/AXWebViewController/AXWebViewController/AXWebViewController.m b/AXWebViewController/AXWebViewController/AXWebViewController.m index 049a9c8..0d7a6aa 100644 --- a/AXWebViewController/AXWebViewController/AXWebViewController.m +++ b/AXWebViewController/AXWebViewController/AXWebViewController.m @@ -413,6 +413,7 @@ - (void)dealloc { _webView.navigationDelegate = nil; [_webView removeObserver:self forKeyPath:@"estimatedProgress"]; [_webView removeObserver:self forKeyPath:@"scrollView.contentOffset"]; + [_webView removeObserver:self forKeyPath:@"title"]; /* [_webView.scrollView removeObserver:self forKeyPath:@"backgroundColor"]; */ @@ -461,6 +462,11 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N // Get the current content offset. CGPoint contentOffset = [change[NSKeyValueChangeNewKey] CGPointValue]; _backgroundLabel.transform = CGAffineTransformMakeTranslation(0, -contentOffset.y-_webView.scrollView.contentInset.top); + } else if ([keyPath isEqualToString:@"title"]) { + // Update title of vc. + [self _updateTitleOfWebVC]; + // And update navigation items if needed. + if (_navigationType == AXWebViewControllerNavigationBarItem) [self updateNavigationItems]; } else { [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } @@ -493,6 +499,8 @@ - (WKWebView *)webView { _webView.navigationDelegate = self; // Obverse the content offset of the scroll view. [_webView addObserver:self forKeyPath:@"scrollView.contentOffset" options:NSKeyValueObservingOptionNew context:NULL]; + // Obverse title. Fix issue: https://github.com/devedbox/AXWebViewController/issues/35 + [_webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL]; return _webView; }