Skip to content

Commit

Permalink
Added title obverser.
Browse files Browse the repository at this point in the history
  • Loading branch information
devedbox committed May 15, 2017
1 parent d1d6522 commit ba0f9d5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions AXWebViewController/AXWebViewController/AXWebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
*/
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit ba0f9d5

Please sign in to comment.