Content pushed down in a UIPageViewController with UINavigationController
So I'm adding another answer after further development and I finally think I figured out what's going on. Seems as though in iOS7, UIPageViewController has its own UIScrollView. Because of this, you have to set automaticallyAdjustsScrollViewInsets
to false. Here's my viewDidLoad
now:
- (void)viewDidLoad{ [super viewDidLoad]; self.automaticallyAdjustsScrollViewInsets = false; DetailViewController *detail = [[DetailViewController alloc] init]; [self setViewControllers:@[detail] direction:UIPageViewControllerNavigationDirectionForward animated:false completion:nil];}
No need to put anything in viewWillLayoutSubviews
(as one of my previous answers suggested).
This is definitely being caused by automaticallyAdjustsScrollViewInsets
, as other posters (including @djibouti33). However, this property is strange in two ways:
- It must be set on a
UINavigationController
. If you set it on a child controller that's managed by aUINavigationController
, it won't have any effect. 1 - It only applies when a scroll view is at index zero in a controller's subviews. 2
These two caveats should explain the intermittent problems experienced by others in the thread.
TLDR: A workaround that I went with is adding a dummy view to the UIPageViewController
at index zero, to avoid the setting applying to the scrollView within the page controller, like this:
pageViewController.view.insertSubview(UIView(), atIndex: 0) // swift[pageViewController.view insertSubview: [UIView new] atIndex: 0]; // obj-c
Better would be to set the contentInset
on the scroll view yourself, but unfortunately the UIPageViewController
doesn't expose the scroll view.
Just uncheck Under Top Bars
for both: UIPageViewController
and your custom PageContentViewController
: