automaticallyAdjustsScrollViewInsets not working

I think that automaticallyAdjustsScrollViewInsets only works when your controllers view is a UIScrollView (a table view is one).

You're problem seems to be that your controller's view is a regular UIView and your UITableView is just a subview, so you'll have to either:

  • Make the table view the "root" view.

  • Adjust insets manually:

    UIEdgeInsets insets = UIEdgeInsetsMake(controller.topLayoutGuide.length,
                                           0.0,
                                           controller.bottomLayoutGuide.length,
                                           0.0);
    scrollView.contentInset = insets;
    

Edit:

Seems like the SDK is capable of adjusting some scroll views despite not being the controller's root view.

So far It works with UIScrollView's and UIWebView's scrollView when they are the subview at index 0.

Anyway this may change in future iOS releases, so you're safer adjusting insets yourself.


Your view controller must be directly on a UINavigaitonController's stack for automaticallyAdjustsScrollViewInsets to work (i.e. not a child view controller)

If it is a child view controller of another view controller which is on the navigation stack, you can instead set automaticallyAdjustsScrollViewInsets = NO on the parent. Alternatively you can do this:

self.parentViewController.automaticallyAdjustsScrollViewInsets = NO;

I just solved this issue with iOS 11 and swift 4, my current problem was that iOS11 has a new property to validate the insets when a ScrollView does exist, that one is contentInsetAdjustmentBehavior which is a ScrollView's property and the default property is automatic so my code was:

if #available(iOS 11, *) {
    myScroll.contentInsetAdjustmentBehavior = .never
} else {
    self.automaticallyAdjustsScrollViewInsets = false
}

I hope this solve your problems too...


I have this hierarchy:

  1. custom navigationcontroller contains custom tabbarcontroller

  2. custom tabbarcontroller contains several controllers

  3. these controllers contains subviews and one of them contains a subclass of uiscrollview.

I had to set automaticallyAdjustsScrollViewInsets to NO

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    self.automaticallyAdjustsScrollViewInsets = NO;

in the custom tabbarcontroller. Other controllers in the hierarchy do not have any impact on the nested scroll view's behavior.