【问题标题】:UISlider to manage UIPageViewController paginationUISlider 管理 UIPageViewController 分页
【发布时间】:2016-03-08 13:25:19
【问题描述】:

我想使用UISlider 控件来管理UIPageViewController 分页。我已经设法获得了页数,这些是滑块用于scroll 分页的值。

现在,它正在工作。当我如此快速地更改值时,问题就来了。任何人都知道我该如何解决这个问题?

- (void)changeValueSlider:(UISlider *)slider {
   [self goToPageAtIndex:slider.value];
}

- (void)goToPageAtIndex:(NSUInteger)index {
    MNBBasePreviewViewController *currentViewController = self.pageViewController.viewControllers.firstObject;
    if (index < self.previewContainerInteractor.count){
        if (index < currentViewController.index) {
            [self backToPageAtIndex:index];
        } else if (index > currentViewController.index) {
            [self forwardToPageAtIndex:index];
        }
    }
}

- (void)forwardToPageAtIndex:(NSUInteger)index {
    MNBBasePreviewViewController *previewViewController = [self viewControllerAtIndex:index];
    [self.pageViewController setViewControllers:@[previewViewController] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];
}

- (void)backToPageAtIndex:(NSUInteger)index {
    MNBBasePreviewViewController *previewViewController = [self viewControllerAtIndex:index];
    [self.pageViewController setViewControllers:@[previewViewController] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:NULL];
}

【问题讨论】:

  • 有什么问题?会发生什么

标签: ios iphone uipageviewcontroller uislider


【解决方案1】:

您可以通过应用以下帖子中的一种技术仅在滑块结束滑动时更新 pageControl:iPhone : How to detect the end of slider drag?

在滑动的同时不断改变值对于这种操作来说风险太大了。如果您真的出于某种原因需要不断更新页面,您将不得不做出一些妥协,这将需要一些努力。 乍一看,我想出了这个策略:

  1. 添加一些 BOOL 属性,我们称其为 'isPresenting' 并最初将其设置为 NO。
  2. 在 sliderValueChange 上,如果 isPresenting 为 NO,则开始呈现视图。
  3. 将属性“isPresenting”设置为 YES。
  4. 当每个视图完成呈现自己时,将 isPresenting 设置为 NO。
  5. 检查滑块是否滑动,如果没有手动调用changeValueSlider:

注意:步骤 4. 和 5. 应该从子视图 (viewDidAppear:) 执行,因此您应该使用协议或本地通知来执行此操作,或者在子视图中引用父视图控制器并调用父视图的方法来自孩子。

【讨论】:

  • 我做的几乎一样。当我调用此方法时出现问题` [self.pageViewController setViewControllers:@[previewViewController] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:NULL]; } `短时间内很多次,一时变得疯狂
  • 这就是我回答的重点,你应该防止它被过于频繁地调用,这就是'isPresenting'属性的用途。您在 viewDidAppear 中的 previewViewController 中将 isPresenting 设置为 NO,并且仅当 isPresenting 为 NO 时才开始新的过渡
  • 嗯,好的,我试试。对不起,我没看懂
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-22
  • 1970-01-01
  • 2016-02-15
  • 2021-06-04
相关资源
最近更新 更多