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