0

我们可以在不改变方向的情况下改变脊椎位置吗?就像对于某些视图,它设置为最大值,对于某些视图,它应该是中间值。是否可以激活此功能。

这是我正在使用的代码,但不知道要在其中修改什么,以便在不改变方向的情况下我可以将脊椎位置设置为最大并设置一页模式而不是两页模式。实际上是在应用程序运行时以两页模式开始的,但后来它需要移动到单页模式,这是不可能的,它给出的错误是您提供一个视图,但需要两个视图。任何人都可以为此指导。

-(id)initWithViewControllers:(NSMutableArray *)Controllers
{
self = [super initWithNibName:nil bundle:nil];
if(self)
{
    self.VControllers =  Controllers;

    pageController = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation: UIPageViewControllerNavigationOrientationHorizontal options:nil];

    self.pageController.view.frame = CGRectMake(12.0f, 10.0f, 748.0f, 985.0f);
    self.pageController.delegate = self;
    self.pageController.dataSource = self;
    [self.pageController setViewControllers:[NSArray arrayWithObject:[VControllers objectAtIndex:0] ] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished)
     {
     }];

    [self addChildViewController:self.pageController];
    [self.view addSubview:self.pageController.view];
    check=YES;
}

return self;
}


 - (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 UIPageViewControllerSpineLocationMax;

 }

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

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
int index = [self.VControllers indexOfObject:viewController];
i=index;
//[self checkViewControllers];
if (index - 1 >= 0)
{
    ind = index;
    return [self.VControllers objectAtIndex:index - 1];
}
return nil;
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
int index = [self.VControllers indexOfObject:viewController];
i=index;

if (index + 1 < [self.VControllers count])
{
    ind = index;
    return [self.VControllers objectAtIndex:index + 1];
}

if (ind1 + 1 < [self.VControllers count])
{
    ind = index;
    return [self.VControllers objectAtIndex:index + 1];
}
return nil;
}
4

1 回答 1

0

如果您想在 UIPageViewController 已经初始化后更改脊椎位置,我认为您可能需要使用新的脊椎位置创建一个新的脊椎位置,并用它替换旧的脊椎位置。

我猜当前的实现只考虑在初始化或改变方向时设置脊椎位置。

您可以为 Apple 打开一个错误,以便他们在未来实施。

于 2012-12-11T08:35:52.387 回答