UIPageViewController 和横屏模式

4

我已经尝试了以下方法,但都没有起作用

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

页面视图选项中的NSLog为2,书脊位置中的NSLog为1。这真的让我很烦恼,我想要的只是用书脊初始化在中间。它总是在左边初始化。应用程序在横向模式下初始化,但只有在将设备旋转180度后,方法“-(UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation”才起作用,然后我可以得到中间的书脊。请问有人可以帮我解决这个问题吗?我已经到处寻找答案了。
我只想让它在横向模式下以书脊居中的方式初始化。
1个回答

8

尝试使用“options”参数:

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

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

...

不要忘记初始化两个内容视图控制器:
NSArray *viewControllers = [NSArray arrayWithObjects:contentViewController1, contentViewController2, nil];

[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接