• On March 9th, I discussed with the big guys in the comments section and thoroughly studied the problem in combination with my project. The root cause is summarized in a word: there is a conflict between the navigation bar return gesture and the ScrollView gesture. In fact, there are two solutions
  • 1: in the specific time, kill UIScrollView gesture, no gesture naturally there is no conflict, I this article is introduced through the inheritance of rewrite UIScrollView function in the specific time to kill their own gesture
  • 2: Change the dependency of the gesture, or the priority of the gesture, so that the nav return gesture takes precedence over the ScrollView gesture.

So in development, there’s a part of the UI that’s going to lay out the UIScrollView horizontally on top of the tableView or some view that’s going to scroll left and right, and the bottom scrollView is going to conflict with the Nav ViewController’s original return gesture

Solution, rewrite the UIScrollView gestureRecognizerShouldBegin in ScrollView rolling round, shielding the ScrollView gesture

class GesturesConflictScrollView: UIScrollView { override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { back(by: gestureRecognizer) } private final func back(by gestureRecognizer: UIGestureRecognizer) -> Bool { guard gestureRecognizer == panGestureRecognizer else { return true } // point.x < 0 On behalf of moving the fingers of the left slide the screen from right to left Instead let as point: CGPoint = panGestureRecognizer. Translation (in: self) let the state: UIGestureRecognizer.State = gestureRecognizer.state let locDistance: CGFloat = UIScreen.main.bounds.size.width if state == .began || state == .possible { let locationPoint = gestureRecognizer.location(in: self) if point.x > 0 && locationPoint.x < locDistance && contentOffset.x <= 0 { return false } let pageCount = contentSize.width / UIScreen.main.bounds.size.width let criticalPoint = pageCount < 2 ? locDistance : locDistance * (pageCount - 1) if point.x < 0 && contentOffset.x == criticalPoint { return false } } return true } }Copy the code