Kyokook Hwang
Kyokook Hwang

Reputation: 2762

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?

Upvotes: 6

Views: 2905

Answers (1)

Kyokook Hwang
Kyokook Hwang

Reputation: 2762

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.

Upvotes: 10

Related Questions