首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS UIPageViewController主干位置

iOS UIPageViewController主干位置
EN

Stack Overflow用户
提问于 2012-07-19 05:31:13
回答 1查看 4.4K关注 0票数 0

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

当我实例化UIPageViewController时,如果设备是横向的,它会创建只有一个页面的UIPageViewController (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 doesnt load...

代码语言:javascript
复制
NSDictionary * options = [NSDictionary dictionaryWithObject:
        [NSNumber numberWithInt:UIPageViewControllerSpineLocationMid]
forKey:UIPageViewControllerOptionSpineLocationKey];

UIPageViewController *pageViewController = [[UIPageViewController alloc]
initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
  navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
                options:options]

有什么问题吗?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2012-12-08 19:19:26

使用此委托。

代码语言:javascript
复制
- (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;
}
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11550686

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档