首页 > 解决方案 > 在 UIPageViewController 中嵌入 UIScrollView 并禁用 pageView 滑动?

问题描述

我有一个UIView子类(图形)嵌入在 a 的UIScrollview内部,UIViewController它是 aUIPageViewController页面之一...我正在尝试禁用滚动,UIPageViewController以便用户扫描滚动以查看图形的最左侧而无需分页背部。我怎样才能做到这一点?ScrollView 甚至是这项工作的正确工具吗? 在此处输入图像描述

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
            }
        }
    }
}

标签: iosswiftuiscrollviewuikituipageviewcontroller

解决方案


你没有显示它的代码,但我假设你实现UIPageViewControllerDataSource了协议并且在某个地方你有方法:

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

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

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


推荐阅读