我能够通过切换来解决这个问题collectionView.isUserInteractionEnabled
。弄清楚在生命周期中的哪个位置执行此操作有点挑战性,最终我最终使用了 UIPageViewControllerDelegatedidFinishAnimating...
所以在我的ContentViewController.viewDidLoad
,我设置collectionView.isUserInteractionEnabled = false
然后在委托中,我需要有条件地启用/禁用集合视图。
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
if completed {
guard let showing = pageViewController.viewControllers?.first as? DayViewController else {
assertionFailure()
return
}
// Disable All
previousViewControllers.forEach {
if let dayVC = $0 as? DayViewController {
dayVC.collectionView?.isUserInteractionEnabled = false
}
}
// Enable Showing
showing.collectionView?.isUserInteractionEnabled = true
} else {
guard let showing = previousViewControllers.first as? DayViewController else {
assertionFailure()
return
}
// Disable All
viewControllers?.forEach {
if let dayVC = $0 as? DayViewController {
dayVC.collectionView?.isUserInteractionEnabled = false
}
}
// Enable Showing
showing.collectionView?.isUserInteractionEnabled = true
}
}