【问题标题】:Can't swipe a `UIPageViewController` with a `UINavigationController`无法使用 `UINavigationController` 滑动`UIPageViewController`
【发布时间】:2016-01-21 20:27:07
【问题描述】:

我有一个带有UIPageViewController 的应用程序,其设置如下:

UINavigationController *navController = (UINavigationController *)[self.storyboard instantiateViewControllerWithIdentifier:@"VCNavController"];
self.navViewControllers = [NSArray arrayWithObjects:navController, nil];

self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"MainPageViewController"];
self.pageViewController.dataSource = self;
self.pageViewController.delegate = self;
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];

if ([self.navViewControllers count] != 0)
{
    [self.pageViewController setViewControllers:@[self.navViewControllers[0]]
                                      direction:UIPageViewControllerNavigationDirectionForward
                                       animated:NO completion:nil];
}

我已经实现了所有必要的委托函数,并且托管 UIPageViewControllerMainViewController 符合 UIPageViewControllerDataSourceUIPageViewControllerDelegate

层次结构

  • MainViewController
    • UIPageViewController
      • UINavigationController
        • UIViewController

我的层次结构中的最后一个UIViewController 显示正确,但是我无法滑动UIPageViewController我没有解释一个明显的原因吗?我在想UINavigationController 可能与委托/数据源提供的委托函数不能很好地配合,或者 @ 987654334@ 干扰触摸。然而,我无法让它工作。

【问题讨论】:

    标签: ios objective-c uiviewcontroller uinavigationcontroller uipageviewcontroller


    【解决方案1】:

    我不明白您为什么需要UINavigationController,这有什么具体原因吗?尝试删除UINavigationController 并将UIViewControllers 直接添加到UIPageViewController。然后处理UIPageViewController中的UIGestures。如果我理解正确,这应该会达到预期的效果。

    【讨论】:

    • 我感觉它会修复它,就像我之前做过的那样 - 但我希望 UINavigationBar 只在一个 UIViewControllers 中
    • 我认为你管理它的唯一方法是让 UIViewController 模仿 UINavigationController。由于 UINavigationController 旨在保持不变并通过数据类型模型应用程序管理导航,因此这可能会导致问题。您可以通过插入 UIViewControllers 并在中间插入 UINavigationController 来检查这一点。如果在 UINavigationController 显示之前滑动有效,那就是问题所在,然后您需要模仿。我希望这会有所帮助并且有意义。
    • 按照您的建议,我通过添加一些额外的UIViewControllers 做了一些试验。然后它起作用了,但我意识到我没有将滚动动画从页面卷曲更改为滚动,因此动画也不正确。我将其更改为滑动,显然这使得在UINavigationController 上滑动也能正常工作!
    • 好吧,完美!对我来说也是很好的信息以供将来参考:)我很高兴我能提供帮助:)
    猜你喜欢
    • 2016-12-07
    • 1970-01-01
    • 2015-07-24
    • 2016-06-12
    • 2013-08-14
    • 1970-01-01
    • 1970-01-01
    • 2019-11-21
    • 2020-09-10
    相关资源
    最近更新 更多