UIPageViewController and landscape

我们两清 提交于 2019-12-23 12:58:08

问题


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


回答1:


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];


来源:https://stackoverflow.com/questions/9246572/uipageviewcontroller-and-landscape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!