UIViewController changes in iOS7

Guides | Thoughts By 4 years ago

UIViewControllers got quite a big change in iOS7. There’s two major changes I want to explore a bit more, and explain in some detail what’s going on.

View frame changes

Because of the blurred bars in iOS7, a UIViewController‘s frame now starts from the very top of the screen (behind the status bar), all the way to the bottom (behind any tab bars, if present). Previously the content would begin below a navigation bar and extend to the top of a tab bar, or to the bottom depending on your UIVC setup. This is a pretty big change. If you build an older app on iOS7, your positioning is probably going to be messed up a bit.

However, this changes again under certain conditions… If your UIViewController is contained within a UINavigationController with it’s navigationBars’ translucent property set to NO, then the content will start from beneath the navigation bar, as per the old way of doing things. Translucency means the view is see through, so obviously if it isn’t then there’s no point extending the view above the bar if it’s not going to make any visual changes. This also applies to a UITabBarController‘s tabBar, where the view controller’s view will only extend up to the top of the bar.

Simple, right?

Scroll view insets

With the frame changes mentioned above, any views placed at origin {0,0} would be behind a navigation bar and status bar. For scroll views, the solution is to set the top and bottom content insets of the scroll view to that of the navigation bar’s maxY and the tab bar’s minY. If you’ve played around with iOS7, you may notice that your scroll views magically work without you actually needing to set the content inset yourself.

By default, a UIViewController will automatically adjust the content insets of it’s UIScrollView (including UITableViews) at view index 0, the very back. This means if there’s a button, label, or any other view behind your table view, you wont get this behaviour for free.

You can also turn off this behaviour by setting the view controller’s automaticallyAdjustsScrollViewInsets property to NO.