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

pageViewOptions 处的 NSlog 为 2,spineLocation 处的 NSlog 为 1。这让我难以忍受,我要做的就是在中间用脊椎初始化。它总是在左边初始化。该应用程序在横向初始化,但只有在将设备旋转 180 度后,方法“- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spinLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation”才起作用,然后我在中间得到脊椎。有人可以对此有所了解。我到处寻找答案。

我想要做的就是在横向初始化,中间有一个脊椎

4

1 回答 1

8

尝试使用“选项”参数:

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

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

...

并且不要忘记初始化 2 个内容视图控制器:

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

[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
于 2012-04-08T15:38:22.123 回答