Skip to content

Laying out content view controllers

Roland Moers edited this page Jun 19, 2014 · 2 revisions

In iOS 7 a new blur effect was added. The frame of a view is extended below bars like the UIToolbar and the UINavigationBar and then visible through the bars with a blur effect applied. RMStepsController supports a similar effect.

(Also take a look at Apples documentation on UIViewController)

Properties to prevent the extension of the view's frame

But sometimes extending the frame of a view is not what is wanted. There are two properties to prevent the extension of the views frame.

Both properties should be set as early as possible as otherwise RMStepsController tries to read them before they are set to their final values. A good point for settings them is in the view controllers init method or in - (NSArray *)stepViewControllers of your RMStepsController subclass.

Property 1

@property(nonatomic, assign) BOOL extendedLayoutIncludesOpaqueBars

This property can be used to switch of the extension of the views frame completely. When set to NO the view is not extended below any bar. When set to YES it is. Default value is NO.

Property 2

@property(nonatomic, assign) UIRectEdge edgesForExtendedLayout
typedef enum : NSUInteger {
   UIRectEdgeNone   = 0,
   UIRectEdgeTop    = 1 << 0,
   UIRectEdgeLeft   = 1 << 1,
   UIRectEdgeBottom = 1 << 2,
   UIRectEdgeRight  = 1 << 3,
   UIRectEdgeAll = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight
} UIRectEdge;

This property can be used for a finer control below which bars the view should be extended. As RMStepsController only has a top bar, it only checks for UIRectEdgeTop.

Example 1

aViewController.edgesForExtendedLayout = UIRectEdgeNone

This example will achieve a similar effect to setting extendedLayoutIncludesOpaqueBars to NO.

Example 2

aViewController.edgesForExtendedLayout = UIRectEdgeTop

In this case the view of aViewController will only be extended below the top bar.

React on the extension of the view's frame

RMStepsController also provides a method to react on the extension of the view's frame. This method is called - (void)adaptToEdgeInsets:(UIEdgeInsets)newInsets. The parameter newInsets contains the number of pixels the view's frame is extended is the direction of every border. This method is added to every UIViewController using a category. The default implementation of this method does nothing.

Example 1: UITableViewController

Let's say your content view controller is an instance of UITableViewController. Then your implementation of this method could look like this:

- (void)adaptToEdgeInsets:(UIEdgeInsets)newInsets {
    self.tableView.contentInset = newInsets;
    self.tableView.scrollIndicatorInsets = newInsets;
}

Here you tell your UITableView the insets for the content and for the scroll indicator and your UITableViewController will adapt its layout automatically. For convenience, RMStepsController already provides an implementation of this method for UITableViewController and UICollectionViewController.