Skip to content

Instantly share code, notes, and snippets.

@grifas
Last active August 3, 2018 08:44
Show Gist options
  • Save grifas/7e912692de787afb669b62b37d3f5fe8 to your computer and use it in GitHub Desktop.
Save grifas/7e912692de787afb669b62b37d3f5fe8 to your computer and use it in GitHub Desktop.
SwipeGesture in scrollView: require to fail.
class ChildViewController: UIViewController {
func addSwipeGesture() {
let leftGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(swipe))
let rightGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(swipe))
leftGestureRecognizer.delegate = self
rightGestureRecognizer.delegate = self
leftGestureRecognizer.direction = UISwipeGestureRecognizerDirection.left
rightGestureRecognizer.direction = UISwipeGestureRecognizerDirection.right
view.addGestureRecognizer(leftGestureRecognizer)
view.addGestureRecognizer(rightGestureRecognizer)
parentScrollView.panGestureRecognizer.require(toFail: leftGestureRecognizer)
parentScrollView.panGestureRecognizer.require(toFail: rightGestureRecognizer)
}
}
extension ChildViewController: UIGestureRecognizerDelegate {
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
// return true/false to enable/disable the left/right gesture
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment