Jack Humphries
Jack Humphries

Reputation: 13267

UIPageViewController resets to first page on rotation

When the user rotates their device, the UIPageViewController fades from whatever page it is displaying back to the first page. This is really annoying, especially when the user is multiple pages into the document. It only occurs in iOS 6.

When the user rotates their device, spineLocationForInterfaceOrientation is called, which probably has something to do with the issue.

- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController
               spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation {

    return UIPageViewControllerSpineLocationMin;

}

I always want the spine to be on the left.

Do you have any idea what is causing the UIPageViewController to reset? I found a bug report here, but I have been unable to find any other information online, leaving me to think that I am doing something wrong.

Upvotes: 3

Views: 1432

Answers (3)

Aaron Edrupt
Aaron Edrupt

Reputation: 1

I had the same issue. I found simply removing my implementation of spineLocationForInterfaceOrientation fixed it for me.

Upvotes: -1

jcesarmobile
jcesarmobile

Reputation: 53301

your spineLocationForInterfaceOrientation is incomplete

it should be something like this:

- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController
                   spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation
{

        UIViewController *currentViewController = self.pageViewController.viewControllers[0];
        NSArray *viewControllers = @[currentViewController];
        [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];

        return UIPageViewControllerSpineLocationMin;

}

Upvotes: 2

Fernando Mazzon
Fernando Mazzon

Reputation: 3591

I'm not aware that such a bug exists, but worst case scenario, you could override

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;

to capture the old state and re-set it after the transition is done. I'm tempted to believe there's something else causing the issue, but without more data, I can't tell. Can you post more of the UIPageViewController code?

Upvotes: 2

Related Questions