I have a view controller set up programmatically which has a child UIPageViewController
. This displays various other view controllers that are also set up programmatically. These view controllers' views have translatesAutoresizingMaskIntoConstraints
set to YES
, but the page view controller's view uses constraints to position itself in the top view controller.
The problem is, when the user rotates the device the page view controller resizes its frame but its child view controllers don't. By didRotateFromInterfaceOrientation
, its frame is still from the old orientation. I've verified that the rotation methods are called on the child view controllers, their frame just doesn't change.
I set up the page view controller like this:
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.view.backgroundColor = [UIColor clearColor];
self.pageViewController.view.translatesAutoresizingMaskIntoConstraints = NO;
self.pageViewController.dataSource = self;
self.pageViewController.delegate = self;
[self.pageViewController willMoveToParentViewController:self];
[self.view addSubview:self.pageViewController.view];
[self addChildViewController:self.pageViewController];
[self.pageViewController didMoveToParentViewController:self];
self.currentPageIndex = 0;
self.currentPageController = [self pageForIndex:self.currentPageIndex];
self.currentPageController.delegate = self;
[self.pageViewController setViewControllers:@[self.currentPageController] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL];
I've tried calling setNeedsLayout
but it's a clumsy rotation animation and the next page that I swipe to is also not resized properly.
Why is the page view controller not resizing its child view controllers, and how do I get it to do this?
Thanks!