在UIPageViewController中嵌入UIScrollView并禁用pageView滑动?

时间:2018-05-22 14:50:13

标签: ios swift uiscrollview uikit uipageviewcontroller

我有一个UIView子类(图表)嵌入UIScrollviewUIViewController内部UIPageViewController页面之一......我&# 39; m尝试禁用UIPageViewController的滚动,以便用户扫描滚动以查看图表的最左侧,而无需回页。我怎样才能做到这一点? ScrollView甚至是这项工作的正确工具吗? enter image description here

class HistoricalHealthDataViewController: UIViewController, UIScrollViewDelegate {


    @IBOutlet weak var graphScrollView: UIScrollView!

    @IBOutlet weak var hockeyTrackerGraphView: HockeyTrackerGraphView! {
        didSet {
            self.hockeyTrackerGraphView.graphableObjects = HFRGraphableObjects
        }
    }


    var HFRGraphableObjects: [HockeyTrackerGraphableObject] = [] 





    override func viewDidLoad() {
        super.viewDidLoad()

        graphScrollView.delegate = self


    }

    func scrollViewDidScroll(_ scrollView: UIScrollView) {

        if let parentPageViewController = parent as? HistoricalPageViewController {

            for gestureRecognizer in parentPageViewController.gestureRecognizers {
                print("gestureRecognizer")
                gestureRecognizer.isEnabled = false
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您没有显示代码,但是我假设您实现了UIPageViewControllerDataSource协议,并且在某处您拥有方法:

func pageViewController(UIPageViewController, viewControllerBefore: UIViewController) -> UIViewController? {
}

func pageViewController(UIPageViewController, viewControllerAfter: UIViewController) -> UIViewController? {
}

如果安排禁用分页时这些方法返回nil,则页面视图将不会滚动到其他页面。