Skip to content

Commit

Permalink
Fixed the issue which the scroll view's content inset changed when tr…
Browse files Browse the repository at this point in the history
…igger the back action on iOS 10.2.
  • Loading branch information
devedbox committed Jan 1, 2017
1 parent e5ff530 commit 8ce832e
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions AXWebViewController/AXWebViewController/AXWebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ - (instancetype)initWithHTMLString:(NSString *)HTMLString baseURL:(NSURL *)baseU

- (void)viewDidLoad {
[super viewDidLoad];

self.automaticallyAdjustsScrollViewInsets = YES;
// Change auto just scroll view insets to NO to fix issue: https://github.com/devedbox/AXWebViewController/issues/10
self.automaticallyAdjustsScrollViewInsets = NO;
self.extendedLayoutIncludesOpaqueBars = YES;
/* Using contraints to view instead of bottom layout guide.
self.edgesForExtendedLayout = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeRight;
Expand Down Expand Up @@ -319,6 +319,19 @@ - (void)dealloc {
#endif
}

#pragma mark - Override.
- (void)setAutomaticallyAdjustsScrollViewInsets:(BOOL)automaticallyAdjustsScrollViewInsets {
// Auto adjust scroll view content insets will always be false.
[super setAutomaticallyAdjustsScrollViewInsets:NO];
/*
// Remove web view from super view and then set up from beginning.
[self.view removeConstraints:self.view.constraints];
[_webView removeFromSuperview];
// Do set up web views.
[self setupSubviews];
*/
}

#pragma mark - KVO
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
if ([keyPath isEqualToString:@"estimatedProgress"]) {
Expand Down Expand Up @@ -1215,7 +1228,15 @@ - (void)setupSubviews {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
[self.view addSubview:self.webView];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_webView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_webView)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_webView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_webView, topLayoutGuide, bottomLayoutGuide)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[topLayoutGuide][_webView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_webView, topLayoutGuide, bottomLayoutGuide)]];
// Set the content inset of scroll view to the max y position of navigation bar to adjust scroll view content inset.
// To fix issue: https://github.com/devedbox/AXWebViewController/issues/10
/*
UIEdgeInsets contentInset = _webView.scrollView.contentInset;
contentInset.top = CGRectGetMaxY(self.navigationController.navigationBar.frame);
_webView.scrollView.contentInset = contentInset;
*/

UIView *contentView = _webView.scrollView.subviews.firstObject;
[contentView addSubview:self.backgroundLabel];
[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_backgroundLabel(<=width)]" options:0 metrics:@{@"width":@([UIScreen mainScreen].bounds.size.width)} views:NSDictionaryOfVariableBindings(_backgroundLabel)]];
Expand Down

0 comments on commit 8ce832e

Please sign in to comment.