Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPageViewController and landscape

I have been trying the following and nothing is working

NSDictionary *pageViewOptions = [NSDictionary dictionaryWithObjectsAndKeys:UIPageViewControllerOptionSpineLocationKey, [NSNumber numberWithInteger:UIPageViewControllerSpineLocationMid],nil];
NSLog(@"pageViewOptions :%@",pageViewOptions);    

self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:pageViewOptions];    
NSLog(@"spineLocation :%d",self.pageViewController.spineLocation);

the NSlog at pageViewOptions is 2, NSlog at spineLocation is 1. This is driving me up the wall, all i want to do is initialise with spine in the middle. It always initialises on the left. the app is initialised in landscape but only after rotating the device 180 degrees the method "- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation" works and then i get spine in the middle. could someone please shed some light on this. I've searched everywhere for an answer.

all i want it to do is initialise in landscape with a spine in the middle

like image 535
Marwan Kathayer Avatar asked Feb 21 '23 12:02

Marwan Kathayer


1 Answers

Try to use "options" parameter:

NSDictionary *options = (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) ? [NSDictionary dictionaryWithObject: [NSNumber numberWithInteger:UIPageViewControllerSpineLocationMid] forKey: UIPageViewControllerOptionSpineLocationKey] : nil; 

self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:options];

...

And don't forget to initialize 2 content view controllers:

NSArray *viewControllers = [NSArray arrayWithObjects:contentViewController1, contentViewController2, nil];

[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
like image 185
Alexey Prazhenik Avatar answered Mar 05 '23 13:03

Alexey Prazhenik