0

Can we change the spine location without changing orientations. Like for some views it is set to max and for some views it should be mid. Is it possible to active this functionality.

This is the code i am using, but don't know what to modify in it so that without changing orientation i can set spine location to max and set one page mode rather than two page mode. Actually is started with two page mode when app runs but later it requires to move to single page mode, that is not getting possible, it gives error that you are providing one view but than two required. Can anyone guide for this.

-(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;
}
iPhone Programmatically
  • 1,211
  • 2
  • 22
  • 54
  • Can you be more specific? You can use whatever spine location you want on landscape. On portrait however I think you cannot use mid. Though I think your question is more complex than that. – Fábio Oliveira Dec 10 '12 at 14:58
  • what are you talking about? pleased add some info ... i guess its about pageViewControl or something like it – Daij-Djan Dec 10 '12 at 15:02
  • 1
    Ya it is about pageviewcontroller. And problem is spine location is changeable only when orientation gets change. I don't know how can i change it without using spine location method. – iPhone Programmatically Dec 10 '12 at 15:06

1 Answers1

0

If you want to change the spine location after the UIPageViewController is already initialized I think you may need to create a new one, with the new spine location, and replace the old one with it.

I guess the current implementation only considers setting the spine location while initializing or when changing orientations.

You may open a bug for Apple so they implement that in the future.

Fábio Oliveira
  • 2,346
  • 21
  • 30
  • but how to dismiss previous page view controller. –  Dec 11 '12 at 12:11
  • You have to control the change from outside the UIPageViewController. To transition between both I'd follow the solution to this question: http://stackoverflow.com/questions/8146253/animate-change-of-view-controllers-without-using-navigation-controller-stack-su – Fábio Oliveira Dec 11 '12 at 12:43
  • Have you found any solution ?? I'm facing the same problem – Grace Dec 18 '12 at 11:46