Search code examples
iosswiftuipageviewcontroller

Detect UIPageViewController begin swipe


I have a UIPageViewController inside a ViewController which contains a UICollectionView to indicate which page is on, and on didSelectItemAt it sets the child VC to be shown.

I need to disable interactions on UICollectionView while the page view is being touched so there will be no interruptions with the way I handle page selection.

I have tried adding a UISwipeGestureRecognizer and using this method below:

override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
    _delegate?.stopTouches()
}

I haven't found a way to do so up to this point. Any suggestions?


Solution

  • Use the delegate.

    https://developer.apple.com/documentation/uikit/uipageviewcontrollerdelegate

    It tells you when the gesture starts and when it ends.