11

I am using a page view controller to flip through a series of view controller, each of which is instantiated from a storyboard. I basically used the standard page based application code as a basis and built what I needed on top of it. The view controllers I'm flipping through are UITableViewController subclasses or custom view controller's that contain custom scroll views or what not.

The page view controller is embedded in a navigation controller, but none of the view controllers are respecting the top layout guide, even though the constraints are set to the layout guides in the storyboard in the case of my custom view controllers and I thought that the table view controller would manage this automatically. I mean the view's contents start from (0.0, 0.0) instead of where the user can see it. The only thing that works is actually setting the frames of the view controller's views to begin just under the status bar + the navigation bar, but I want the scroll view's to scroll under the transparent navigation bar.

What am I doing wrong or not doing?

Arun_
  • 1,806
  • 2
  • 20
  • 40
kmikael
  • 4,962
  • 3
  • 32
  • 34
  • 1
    This has been discussed a bit here http://stackoverflow.com/questions/19140530/toplayoutguide-in-child-view-controller – Mike Pollard Oct 15 '13 at 11:13

3 Answers3

18

It sounds like you don't want your content view controller's to underlap the navigation and status bars. If that's the case, try setting parent view controller's edgesForExtendedLayout property to UIRectEdgeNone.

// implementation of page view controller's parent view controller
- (void)viewDidLoad
{
    [super viewDidLoad];

    self.pageViewController = ...

    ...

    self.edgesForExtendedLayout = UIRectEdgeNone; // iOS 7 only
}
bilobatum
  • 8,918
  • 6
  • 36
  • 50
  • 6
    I think I do want them to underlap the navigation and status bars. Because they are scroll views, I want them visible under the translucent navigation bar. – kmikael Oct 23 '13 at 18:45
  • @bilobatum how to achieve the effect of self.edgesForExtendedLayout = UIRectEdgeNone; using the storyboard? – dev4life Sep 10 '14 at 18:02
  • 1
    Still relevant in iOS 9. Two years later, we might want to change that comment to "iOS 7 and later" – Mallioch Nov 01 '15 at 13:25
  • 1
    In swift 3, we have to do like this `self.edgesForExtendedLayout = [] ` – Ioan Moldovan Dec 15 '16 at 05:26
8

For me, setting automaticallyAdjustsScrollViewInsets = NO; on the UIPageViewController fixed the issue. You can change that in the Interface Builder, under Attribute Inspector, uncheck "Adjust Scroll View Insets".

Rajan Maharjan
  • 1,137
  • 2
  • 12
  • 22
4

On storyboards:

Uncheck values in parentviewcontollers "Extend Edges" section

Storyboard screenshot

saq
  • 231
  • 1
  • 8