iOS 7 -- navigationController is setting the contentInset and ContentOffset of my UIScrollView

I have a UIScrollView (actually a UICollectionView, but that probably doesn't matter). When it appears in IOS 7, the navigation controller sets its contentInset and contentOffset to values I don't want. It appears to be trying to adjust for the status bar and the navigation bar. I'd greatly prefer it left them alone. I've fixed this by overriding the getter and setter methods for contentInset and contentOffset, with a flag to tell the object whether or not it should accept a set. But is there a better way?


Solution 1:

Try setting self.automaticallyAdjustsScrollViewInsets = NO in your main view controller.

This was introduced in iOS 7 so you might want to wrap that with an iOS version check, if you are supporting iOS 6 and below.


Update

If you are using storyboards, you can do this in the Interface Builder as well as by checking 'Adjust Scroll View Insets' for your selected controller.

enter image description here

Solution 2:

I had a similar problem, after dismissing a viewController, the contentOffset from my tableView was changed to (0, -64).

my solution was a little weird, I tried all the other answers but had no success, the only thing that fixed my problem was to switch the tableView position in the controls tree of the .xib

it was the first control in the parent View like this:

before

I moved the tableView right after the ImageView and it worked:

after

it seems that putting the table view in the first position was causing the trouble, and moving the table view to another position fixed the problem.

P.D. I'm not using autoLayout neither storyboards

hope this can help someone!

Solution 3:

I have two solutions:

1.

self.view = scrollView;

2.

[self.navigationController.toolbar setTranslucent:NO];

Solution 4:

I'm having the same problem.

  1. Setting self.automaticallyAdjustsScrollViewInsets = NO solved the issue for some of the view but not everywhere.

  2. Second solution is to set the content-offset of tableview/view/scrollview in viewWillLayoutSubviews:

    - (void)viewWillLayoutSubviews {
        //Arrange the view
        CGRect tempViewFrame = self.view.frame;
    
        if (tempViewFrame.origin.y == 64.0f) {
            tempViewFrame.origin.y = 0;
            self.view.frame = tempViewFrame;
        }
    }