gpt4 book ai didi

iphone - 将一个(垂直的)UIPageViewController 嵌套在另一个(水平的)UIPageViewcontroller 中

转载 作者:太空狗 更新时间:2023-10-30 03:33:38 25 4
gpt4 key购买 nike

我的 UIPageViewController 有一个大问题。我想使用部分和子部分在我的应用程序中呈现内容。因此,我创建了 UIPageViewController“两个” 实例 - 水平(红色)和垂直(蓝色):

scheme

之前我说过我创建了“两个”实例 - 这并不完全正确 - 可以有数十个实例,但同时只显示 2 个,你知道我的意思。两个 Controller 都将 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接收触摸并双向滚动?

如有任何帮助,我们将不胜感激。

最佳答案

我忘记为我的垂直页面 View Controller 分配 dataSourcedelegate 属性

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

问题已解决,一切正常。

关于iphone - 将一个(垂直的)UIPageViewController 嵌套在另一个(水平的)UIPageViewcontroller 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15039792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com