Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPageViewController on UINavigationController does not relayout its child viewcontroller since changing orientation

I am making the following view controller(VC) structure.

[UINavigationViewController] -> [UIPageViewController] -> [UIViewControllers]

then, this VC should support portrait and landscape orientation.

A problem I have is raised at changing orientation to any sides.

enter image description here

you can see the problem. enter image description here

red area is background color of child VC on UIPageViewController.
blue area is background color of UIPageViewController.

I guess child VC was not relayouted by UIPageViewController. I have figured it out for a long time. I finally ended up finding a work around to add the following overridden function to custom UIPageViewController.

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    [self setViewControllers:self.viewControllers
                   direction:UIPageViewControllerNavigationDirectionForward
                    animated:NO
                  completion:NULL];
}

Although moving a view to downside is showed as soon as finishing rotation. This code solves the problem roughly.

anyway, I really want to know any nice and natural solutions.

UPDATE
My app works well on iOS6. it may be iOS7 bug?

like image 596
Kyokook Hwang Avatar asked Nov 03 '13 17:11

Kyokook Hwang


1 Answers

I have solved this problem to place the following SINGLE line of code in [viewDidLoaded] of custom UIPageViewController.

self.automaticallyAdjustsScrollViewInsets = NO;

I supposed that UIPageViewController has a scroll view, and if it is embedded in UINavigationController, it will lay out incorrectly since changing orientation.

Fortunately, my solution fitted in the problem.

@MirkoCatalano Thank you for your comments. these are very helpful to found out right solution.

like image 155
Kyokook Hwang Avatar answered Sep 20 '22 10:09

Kyokook Hwang