gpt4 book ai didi

ios - UIPageViewController 缓存

转载 作者:行者123 更新时间:2023-12-01 18:59:12 30 4
gpt4 key购买 nike

我有一个带有动态变化数据源的 UIPageViewController -

viewControllerAfterViewController



viewControllerBeforeViewController

如果数据还没有准备好,则返回 nil,如果准备好,则返回 View Controller 。如果我尝试在某些时候快速向左翻页多次 viewControllerAfterViewController 将不再被调用。

可能是什么问题?我想 UIPageViewController 认为它知道一切并且什么都没有改变,所以它不调用那个方法,对吗?我怎样才能“重置”这个缓存?

我使用 curl 过渡风格,这似乎只发生在横向模式下。

最佳答案

我最终使用了自己的滑动手势。

  • 首先从 UIPageViewController 中删除现有的滑动手势
    for (UIGestureRecognizer * recognizer in _pageViewController.gestureRecognizers) {
    recognizer.enabled = NO;
    }
  • 然后将您自己的滑动手势识别器添加到 UIPageViewController
    UISwipeGestureRecognizer * rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSwipe:)];
    [rightRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
    [_pageViewController.view addGestureRecognizer:rightRecognizer];

    UISwipeGestureRecognizer * leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSwipe:)];
    [leftRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
    [_pageViewController.view addGestureRecognizer:leftRecognizer];

    - (void) handleRightSwipe: (id) sender {
    // your swipe handler here
    // note that you need to call didFinishAnimating manually now

    // manually calculate next/prev view controller, also you should consider orientation too
    UIViewController * nextController = [_modelController pageViewController:_pageViewController viewControllerAfterViewController:existingController];


    __weak typeof(self) weakSelf = self;
    __weak UIPageViewController * wController = _pageViewController;
    [_pageViewController setViewControllers:@[nextController] direction:
    UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL completed){
    [weakSelf pageViewController:wController didFinishAnimating:YES previousViewControllers:@[existingController] transitionCompleted:YES];
    }];
    }
    }

  • 此外,您可以尝试不删除现有的滑动手势,如果现有识别器触发,它看起来不会调用您的自定义滑动手势,这样您在拖动页面角落时也有很好的动画(如果您删除所有识别器)。

    关于ios - UIPageViewController 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24034454/

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