Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
With the release of iOS 7, Apple introduced a host of new features and APIs that aimed to provide developers with more control and flexibility over the layout and behavior of their applications. Among these are three properties: `automaticallyAdjustsScrollViewInsets`, `extendedLayoutIncludesOpaqueBars`, and `edgesForExtendedLayout`. These properties are essential for developers working on user interfaces in iOS applications, especially those utilizing `UINavigationBar` and `UITabBar`.
automaticallyAdjustsScrollViewInsets
Overview
The `automaticallyAdjustsScrollViewInsets` property is a Boolean value that, when set to `YES`, allows a view controller to adjust the scroll view's content insets automatically. This is particularly useful when working with `UITableView` or `UICollectionView`, as it helps ensure that scrollable content is not obscured by navigation bars, tab bars, or status bars.
Technical Explanation
- Default Behavior: By default, `automaticallyAdjustsScrollViewInsets` is set to `YES`. This means that if a view controller has a scroll view, the system will automatically adjust the content insets to account for the top and bottom bars.
- Customization: If you set it to `NO`, you must manually adjust the content insets to prevent the scroll view's content from being obscured by the layout bars.
Example
- Default Behavior: By default, this property is set to `NO`, meaning that if the navigation bar is opaque, the view controller's view does not extend beneath it.
- Usage: Setting this property to `YES` can be beneficial when you want the content to appear beneath bars, allowing for a more immersive user experience, such as with translucent designs.
- Default Behavior: The default value is `UIRectEdgeAll`, meaning the view controller's view can freely extend in all directions.
- Customization: Use this property to control specific edges that should be extended beneath bars. This is especially useful when dealing with complex layouts where only certain parts of the view should extend.
- Legacy Approach: Manually adjusting insets using properties like `automaticallyAdjustsScrollViewInsets` and `edgesForExtendedLayout`.
- Modern Approach: Utilizing `safeAreaInsets` and `contentInsetAdjustmentBehavior` for adaptive layout adjustments.

