0

how to block swipe gesture of UIPageViewController?

pageViewController.view.isUserInteractionEnabled = false

private func setupPageController() {
    pageViewController = UIPageViewController(transitionStyle:.pageCurl, navigationOrientation: .horizontal, options: nil)
    pageViewController.delegate = self
    pageViewController.dataSource = nil
    pageViewController.view.isUserInteractionEnabled = false



    viewControllers = [
        storyboard!.instantiateViewController(withIdentifier: "MyProfile"),
        storyboard!.instantiateViewController(withIdentifier: "Sync"),
        storyboard!.instantiateViewController(withIdentifier: "Assistance"),
        storyboard!.instantiateViewController(withIdentifier: "ChangePassword"),
        storyboard!.instantiateViewController(withIdentifier: "ContactUs"),
        storyboard!.instantiateViewController(withIdentifier: "SpeedTest"),
        storyboard!.instantiateViewController(withIdentifier: "Help")

    ]

    pageViewController.setViewControllers([viewControllerAtIndex(0)!], direction: .forward, animated: true, completion: nil)
    pageViewController.dataSource = self



    addChildViewController(pageViewController)
    view.addSubview(pageViewController.view)

    pageViewController!.view.frame = CGRect(x: 0, y:110, width: view.bounds.width, height: view.bounds.height - 70)//view.bounds
    pageViewController.didMove(toParentViewController: self)

    // Add the page view controller's gesture recognizers to the view controller's view so that the gestures are started more easily.

    // view.gestureRecognizers = pageViewController.gestureRecognizers
}
Let's_Create
  • 2,963
  • 3
  • 14
  • 33
  • 1
    Possible duplicate of [How do I Disable the swipe gesture of UIPageViewController?](https://stackoverflow.com/questions/22098493/how-do-i-disable-the-swipe-gesture-of-uipageviewcontroller) – Let's_Create Jul 10 '19 at 06:57
  • use this solution but not work. – Dinesh Kokare Jul 10 '19 at 07:21
  • Please share what exact problem you are getting. According to your question, it seems it similar to the other question. – Let's_Create Jul 10 '19 at 07:31
  • Disabling the data source causes problems I cant manages navigation between pages of content, where each page is managed by a child view controller. – Dinesh Kokare Jul 10 '19 at 07:43

1 Answers1

0

You can use the below extension enable or disable the SwipeGesture

extension UIPageViewController {

    func enableSwipeGesture() {
        for view in self.view.subviews {
            if let subView = view as? UIScrollView {
                subView.isScrollEnabled = true
            }
        }
    }

    func disableSwipeGesture() {
        for view in self.view.subviews {
            if let subView = view as? UIScrollView {
                subView.isScrollEnabled = false
            }
        }
    }
}
Vicky_Vignesh
  • 584
  • 2
  • 14