This is due to UIScrollView's
(UITableView is a subclass of UIScrollview) new contentInsetAdjustmentBehavior
property, which is set to .automatic
by default.
You can override this behavior with the following snippet in the viewDidLoad of any affected controllers:
tableView.contentInsetAdjustmentBehavior = .never
https://developer.apple.com/documentation/uikit/uiscrollview/2902261-contentinsetadjustmentbehavior
In addition to maggy's answer
OBJECTIVE-C
if (@available(iOS 11.0, *)) {
scrollViewForView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
This issue was caused by a bug in iOS 11 where the
safeAreaInsets
of the view controller's view were set incorrectly during the navigation transition, which should be fixed in iOS 11.2. Setting thecontentInsetAdjustmentBehavior
to.never
isn't a great workaround because it will likely have other undesirable side effects. If you do use a workaround you should make sure to remove it for iOS versions >= 11.2-mentioned by smileyborg (Software Engineer at Apple)
You can edit this behavior at once throughout the application by using NSProxy in for example didFinishLaunchingWithOptions:
if (@available(iOS 11.0, *)) {
[UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
Here's how I managed to fix this issue while still allowing iOS 11 to set insets automatically. I am using UITableViewController
.
tableView.insetsContentViewsToSafeArea = true
) - This might not be necessary but it's what I did.tableView.contentInsetAdjustmentBehavior = .scrollableAxes
) - .always
might also work but I did not test.One other thing to try if all else fails:
Override viewSafeAreaInsetsDidChange
UIViewController
method to get the table view to force set the scroll view insets to the safe area insets. This is in conjunction with the 'Never' setting in Maggy's answer.
- (void)viewSafeAreaInsetsDidChange {
[super viewSafeAreaInsetsDidChange];
self.tableView.contentInset = self.view.safeAreaInsets;
}
Note: self.tableView
and self.view
should be the same thing for UITableViewController
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With