我有一个UIView
子类(图表)嵌入UIScrollview
内UIViewController
内部UIPageViewController
页面之一......我&# 39; m尝试禁用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
}
}
}
}
答案 0 :(得分:0)
您没有显示代码,但是我假设您实现了UIPageViewControllerDataSource
协议,并且在某处您拥有方法:
func pageViewController(UIPageViewController, viewControllerBefore: UIViewController) -> UIViewController? {
}
func pageViewController(UIPageViewController, viewControllerAfter: UIViewController) -> UIViewController? {
}
如果安排禁用分页时这些方法返回nil,则页面视图将不会滚动到其他页面。