Почему я не могу остановить анимацию скручивания страницы в UIPageViewController - PullRequest
2 голосов
/ 30 апреля 2019

Я пытаюсь использовать UIPageViewController для перемещения между контроллерами. Все работает нормально, но единственная проблема заключается в том, что я меняю стиль перехода в раскадровке с прокрутки страницы на прокрутку. Но это не работает. Когда я запускаю приложение и перемещаюсь между контроллерами, анимация вызывает скручивание страницы !!!

мой код прост, вы можете проверить его:

override func viewDidLoad() {
        super.viewDidLoad()             
        let firstViewController = orderedViewControllers[1]
        setViewControllers([firstViewController],
                               direction: .forward,
                               animated: false,
                               completion: nil) 
        self.delegate = self
        self.dataSource = self 
    }

func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
        guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
            return nil
        }

        let previousIndex = viewControllerIndex - 1

        // User is on the first view controller and swiped left to loop to
        // the last view controller.
        guard previousIndex >= 0 else {
             return nil
        }

        guard orderedViewControllers.count > previousIndex else {
            return nil
        }
        return orderedViewControllers[previousIndex]
    }

    func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
        guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
            return nil
        }

        let nextIndex = viewControllerIndex + 1
        let orderedViewControllersCount = orderedViewControllers.count

        // User is on the last view controller and swiped right to loop to
        // the first view controller.
        guard orderedViewControllersCount != nextIndex else {
             return nil
        }

        guard orderedViewControllersCount > nextIndex else {
            return nil
        }
        return orderedViewControllers[nextIndex]
    }
    ```

1 Ответ

2 голосов
/ 30 апреля 2019

Вам нужно изменить это transitionStyle при создании экземпляра вашего контроллера

PageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal)
...