UIPageViewController和景观
问题描述:
我一直在尝试以下,并没有什么工作UIPageViewController和景观
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的在pageViewOptions是2,在NSLog的是spineLocation 1.这是推动我逼疯了,我想要做的是在脊柱中间初始化。它总是在左边初始化。该应用程序被初始化景观,但只有旋转设备180度的方法 后“ - (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)方向” 作品,然后我得到的中间脊椎。有人可以请说明这一点。我到处寻找答案。
所有我希望它做的是在景观初始化与脊椎中间
答
尝试使用“选项”参数:
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];