UIPageviewController - 在不改变方向的情况下从两种页面模式切换到一种页面模式 [英] UIPageviewController - Change from two page mode to one page mode without changing orientation

查看:99
本文介绍了UIPageviewController - 在不改变方向的情况下从两种页面模式切换到一种页面模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UIPageViewController一次显示两个视图控制器。在显示几个这样的视图后,我想显示单视图控制器而不改变方向,它固定为横向。我在iPad上制作。

I am using UIPageViewController to show two view controllers at a time. After showing a couple of such views, i want to show single view controllers without changing orientation, it is fixed to landscape. I am making in iPad.

以下是我正在使用的代码:

Below is the code i am using 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];   
}
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 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;
}
}


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

//[self checkViewControllers];
if (index - 1 >= 0)
{
    ind = index;
    return [self.VControllers objectAtIndex:index - 1];
}
ind = index;
return nil;
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
int index = [self.VControllers indexOfObject:viewController];
//[self checkViewControllers];
if (index + 1 < [self.VControllers count])
{
    ind = index;
    return [self.VControllers objectAtIndex:index + 1];
}
ind = index;

return nil;
}

我需要的是在显示双视图后显示单个视图控制器时间此功能我无法激活。任何人都可以为此提供指导。

What i need is to show the single view controllers after shows double views a couple of time. This functionality i am unable to active yet. Can anyone guide for this .

提前致谢。

推荐答案

您无法在不更改方向的情况下从显示两个页面更改为仅显示一个页面。

You cannot change from showing two pages to showing just one page without changing the orientation.

您可以做的是创建自己的容器并自行处理转换。虽然我不能提供自己的任何示例代码,但它看起来比看起来容易。

What you can do is to create your own container and deal with the transitions yourself. Is easier than it looks although I cannot provide with any sample code from myself.

但是我可以通过谷歌搜索找到一些我能找到的教程:

However I can show some tutorials I was able to find with some googling:

  • http://www.cocoanetics.com/2012/04/containing-viewcontrollers/;
  • How does View Controller Containment work in iOS 5?;
  • http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html;
  • http://www.slideshare.net/bobmccune/creating-container-view-controllers#btnNext;
  • http://highoncoding.com/Articles/848_Creating_iPad_Dashboard_Using_UIViewController_Containment.aspx.

如果你想获得翻页效果,你可能会看到这里

If you want to have the page turning effect you may look here.

这样你就有了自由显示您想要的视图控制器数量,并随时更改该数字。这样做甚至可以制作动画。

With this you'll have the freedom to show how many view controllers you want and change that number whenever. And you can even animate when doing that.

这篇关于UIPageviewController - 在不改变方向的情况下从两种页面模式切换到一种页面模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆