我在UIView页面之一的UIScrollview内的UIViewController内嵌入了UIPageViewController子类(图形)...我试图禁止UIPageViewController滚动用户扫描滚动条即可看到图形的最左端,而无需返回页面。我怎样才能做到这一点? ScrollView甚至是这项工作的正确工具吗? ios - 将UIScrollView嵌入到UIPageViewController内并禁用pageView滑动?-LMLPHP

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

最佳答案

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

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

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


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

10-01 20:12