8

我的UIPageViewController有一个很大的问题。我想要使​​用部分和子部分在我的应用中呈现内容。所以,我创建“两化”UIPageViewController实例 - 水平(红色)和纵向(蓝色):将(垂直)UIPageViewController嵌套在另一个(水平)UIPageViewcontroller中

scheme

早些时候我说我已经创建了“两化”情况 - 这是不完全正确 - 可以有几十个实例,但只有两个同时出现,你知道我的意思是。两个控制器都有transitionStyle设为UIPageViewControllerTransitionStyleScroll

红色UIPageViewController负责部分之间的水平滚动,蓝色负责垂直滚动。

他们两个工作时分开,但当我把垂直UIPageViewController水平,垂直一停止工作

我的代码是介绍如下:


水平UIPageViewController创作

self.mainPageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:@{UIPageViewControllerOptionInterPageSpacingKey:[NSNumber numberWithFloat:0]}]; 
self.mainPageViewController.dataSource = self; 
self.mainPageViewController.delegate = self; 

self.pdfDocsURLs = @[ @{@"v":[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"1v" ofType:@"pdf"]], 
         @"h":[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"1h" ofType:@"pdf"]]}, 

         @{@"v":[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"2v" ofType:@"pdf"]], 
         @"h":[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"2h" ofType:@"pdf"]]}, 

         @{@"v":[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"3v" ofType:@"pdf"]], 
         @"h":[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"3h" ofType:@"pdf"]]}]; 

UIIndexedPageViewController *pvc = [[UIIndexedPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationVertical options:@{UIPageViewControllerOptionInterPageSpacingKey:[NSNumber numberWithFloat:0]}]; 
pvc.index = 1; 
PDFDocument *vdoc = [[PDFDocument alloc] initWithPDFFileURL:self.pdfDocsURLs[0][@"v"] password:nil]; 
PDFDocument *hdoc = [[PDFDocument alloc] initWithPDFFileURL:self.pdfDocsURLs[0][@"h"] password:nil]; 
PDFSinglePageViewController *svc = [[PDFSinglePageViewController alloc] initWithVerticalPDF:vdoc horizontalPDF:hdoc page:1]; 
[pvc setViewControllers:@[svc] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; 

[self.mainPageViewController setViewControllers:@[pvc] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; 

只是要清楚,UIIndexedPageViewController是UIPVC的额外NSUInteger index属性的子类。它的实现是空的 - 它不会覆盖任何方法。


UIPageViewController数据源的方法

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { 
    if(pageViewController == self.mainPageViewController) { // if horizontal 
     UIIndexedPageViewController *ivc = (UIIndexedPageViewController *)viewController; 
     if(ivc.index == self.pdfDocsURLs.count) return nil; 
     UIIndexedPageViewController *pvc = [[UIIndexedPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationVertical options:@{UIPageViewControllerOptionInterPageSpacingKey:[NSNumber numberWithFloat:0]}]; 
     pvc.index = ivc.index+1; 
     PDFDocument *vdoc = [[PDFDocument alloc] initWithPDFFileURL:self.pdfDocsURLs[ivc.index][@"v"] password:nil]; 
     PDFDocument *hdoc = [[PDFDocument alloc] initWithPDFFileURL:self.pdfDocsURLs[ivc.index][@"h"] password:nil]; 
     PDFSinglePageViewController *svc = [[PDFSinglePageViewController alloc] initWithVerticalPDF:vdoc horizontalPDF:hdoc page:1]; 
     [pvc setViewControllers:@[svc] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; 
     return pvc; 
    } else { // if vertical - THE CODE BELOW IS NEVER EXECUTED 
     PDFSinglePageViewController *ovc = (PDFSinglePageViewController *)viewController; 
     NSUInteger nop = 0; 
     if(UIInterfaceOrientationIsPortrait(ovc.interfaceOrientation)) nop = ovc.verticalDoc.numberOfPages; 
     else if(UIInterfaceOrientationIsLandscape(ovc.interfaceOrientation)) nop = ovc.horizontalDoc.numberOfPages; 
     if(ovc.page == nop) return nil; 
     PDFSinglePageViewController *svc = [[PDFSinglePageViewController alloc] initWithVerticalPDF:ovc.verticalDoc horizontalPDF:ovc.horizontalDoc page:ovc.page+1]; 
     return svc; 
    } 
} 

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController { 
    if(pageViewController == self.mainPageViewController) { // if horizontal 
     UIIndexedPageViewController *ivc = (UIIndexedPageViewController *)viewController; 
     if(ivc.index == 1) return nil; 
     UIIndexedPageViewController *pvc = [[UIIndexedPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationVertical options:@{UIPageViewControllerOptionInterPageSpacingKey:[NSNumber numberWithFloat:0]}]; 
     pvc.index = ivc.index-1; 
     PDFDocument *vdoc = [[PDFDocument alloc] initWithPDFFileURL:self.pdfDocsURLs[ivc.index-2][@"v"] password:nil]; 
     PDFDocument *hdoc = [[PDFDocument alloc] initWithPDFFileURL:self.pdfDocsURLs[ivc.index-2][@"h"] password:nil]; 
     PDFSinglePageViewController *svc = [[PDFSinglePageViewController alloc] initWithVerticalPDF:vdoc horizontalPDF:hdoc page:1]; 
     [pvc setViewControllers:@[svc] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; 
     return pvc; 
    } else { // is vertical - THE CODE BELOW IS NEVER EXECUTED 
     PDFSinglePageViewController *ovc = (PDFSinglePageViewController *)viewController; 
     NSUInteger nop = 0; 
     if(UIInterfaceOrientationIsPortrait(ovc.interfaceOrientation)) nop = ovc.verticalDoc.numberOfPages; 
     else if(UIInterfaceOrientationIsLandscape(ovc.interfaceOrientation)) nop = ovc.horizontalDoc.numberOfPages; 
     if(ovc.page == 1) return nil; 
     PDFSinglePageViewController *svc = [[PDFSinglePageViewController alloc] initWithVerticalPDF:ovc.verticalDoc horizontalPDF:ovc.horizontalDoc page:ovc.page-1]; 
     return svc; 
    } 
} 

如此看来,水平UIPageViewController不允许纵向一来,即使接收平移手势识别。


我的问题是...有没有办法,让垂直UIPageViewController接收触摸和滚动两个方向?

任何帮助,将不胜感激。

+0

感谢您的有用问题的方向。做类似的事情。 – san 2014-10-11 13:52:24

回答

3

我忘了在

  • -pageViewController:viewControllerBeforeViewController:
  • -pageViewController:viewControllerAfterViewController:

问题解决了分配我的垂直页面视图控制器的dataSourcedelegate性质,一切精美的作品。