Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS UIPageViewController脊椎位置_Ios_Uipageviewcontroller - Fatal编程技术网

iOS UIPageViewController脊椎位置

iOS UIPageViewController脊椎位置,ios,uipageviewcontroller,Ios,Uipageviewcontroller,我正在实现一个UIPageViewController,即使我在初始化后旋转设备,它也可以正常工作。它正确地设置了SpineLocation,但是 当我实例化UIPageViewController时,如果设备处于横向,它将创建只有一个页面的UIPageViewController(UIPageViewControllerSpineLocationMin) 我尝试使用UIPageViewControllerSpineLocationMid来实例化它,就像下面的代码一样(就像developer.a

我正在实现一个UIPageViewController,即使我在初始化后旋转设备,它也可以正常工作。它正确地设置了SpineLocation,但是

当我实例化UIPageViewController时,如果设备处于横向,它将创建只有一个页面的UIPageViewController(UIPageViewControllerSpineLocationMin)

我尝试使用UIPageViewControllerSpineLocationMid来实例化它,就像下面的代码一样(就像developer.apple推荐的那样),但是当我这样做的时候。。。UIPageViewController不加载

NSDictionary * options = [NSDictionary dictionaryWithObject:
        [NSNumber numberWithInt:UIPageViewControllerSpineLocationMid]
forKey:UIPageViewControllerOptionSpineLocationKey];

UIPageViewController *pageViewController = [[UIPageViewController alloc]
initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
  navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
                options:options]
有什么不对劲吗? 谢谢

使用此委托

- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController  *)pageViewController
               spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation
{
if(UIInterfaceOrientationIsPortrait(orientation))
{
 //Set the array with only 1 view controller
    UIViewController *currentViewController = [self.pageController.viewControllers objectAtIndex:0];
    NSArray *viewControllers = [NSArray arrayWithObject:currentViewController];
    [self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];

    //Important- Set the doubleSided property to NO.
    self.pageController.doubleSided = NO;
    //Return the spine location
    return UIPageViewControllerSpineLocationMin;

 }

else
{
NSArray *viewControllers = nil;

    exampleViewController *currentViewController = [self.pageController.viewControllers objectAtIndex:0];

    NSUInteger currentIndex = [self.VControllers indexOfObject:currentViewController];

    if(currentIndex == 0 || currentIndex %2 == 0)
    {
        UIViewController *nextViewController = [self pageViewController:self.pageController viewControllerAfterViewController:currentViewController];
        viewControllers = [NSArray arrayWithObjects:currentViewController, nextViewController, nil];
    }
    else
    {
        UIViewController *previousViewController = [self pageViewController:self.pageController viewControllerBeforeViewController:currentViewController];
        viewControllers = [NSArray arrayWithObjects:previousViewController, currentViewController, nil];
    }
    //Now, set the viewControllers property of UIPageViewController
    [self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];

    return UIPageViewControllerSpineLocationMid;
}
}