Reputation: 1
I`m implementing an UIPageViewController and all works fine even if i rotate the device after the initialization it sets the SpineLocation correctly, BUT
When i Instantiate the UIPageViewController, IF the device is on landscape orientation it creates the UIPageViewController with just one page (UIPageViewControllerSpineLocationMin)...
Im trying to instantiate it using UIPageViewControllerSpineLocationMid just like the code below (and like developer.apple recommends) BUT when i do it... the UIPageViewController doesn
t load...
NSDictionary * options = [NSDictionary dictionaryWithObject:
[NSNumber numberWithInt:UIPageViewControllerSpineLocationMid]
forKey:UIPageViewControllerOptionSpineLocationKey];
UIPageViewController *pageViewController = [[UIPageViewController alloc]
initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:options]
Is there something wrong? Thanks!
Upvotes: 0
Views: 4490
Reputation: 1227
Use this delegate.
- (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;
}
}
Upvotes: 2