繁体   English   中英

如何快速阻止 UIPageViewController 的滑动手势?

[英]how to block swipe gesture of UIPageViewController in swift?

如何阻止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
}

您可以使用以下扩展启用或禁用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
            }
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM