Вложение (вертикального) UIPageViewController в другой (горизонтальный) UIPageViewcontroller

У меня большая проблема с моим UIPageViewController. Я хочу представить контент в своем приложении с помощью разделов и подразделов. Итак, я создал "два" экземпляра UIPageViewController - горизонтальный (красный) и вертикальный (синий):

схема

Ранее я сказал, что создал "два" экземпляра - это не совсем так - экземпляров может быть десятки, а представлены только 2 одновременно, вы понимаете, о чем я. На обоих контроллерах 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 принимать касания и прокручивать в обоих направлениях?

Любая помощь будет оценена по достоинству.


person akashivskyy    schedule 23.02.2013    source источник
comment
спасибо за направление в вашем полезном вопросе. делать что-то подобное.   -  person san    schedule 11.10.2014


Ответы (1)


Я забыл назначить свойства dataSource и delegate моих вертикальных контроллеров просмотра страниц в

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

Проблема решена, все работает прекрасно.

person akashivskyy    schedule 23.02.2013