Skip to content

Instantly share code, notes, and snippets.

@guzhenhuaGitHub
Last active June 14, 2019 10:49
Show Gist options
  • Save guzhenhuaGitHub/6f571013f1656eb0e33748fcf898a3ad to your computer and use it in GitHub Desktop.
Save guzhenhuaGitHub/6f571013f1656eb0e33748fcf898a3ad to your computer and use it in GitHub Desktop.
解决scrollView右滑与系统右滑返回上级页面手势冲突
/// 解决视图右滑与系统右滑返回上级页面手势冲突
protocol PopGestureConflictProtocol {
}
extension UIViewController: PopGestureConflictProtocol {}
extension PopGestureConflictProtocol where Self: UIViewController {
/// 处理scrollView和系统右滑返回手势的冲突
///
/// 虽然self可能是某个UIViewController的子视图,但是不用管它。直接处理navigationController的手势冲突就行了
/// 因为我发现这么一个神奇的情况:
/// navigationController -[embed]-> viewController -[embed]-> subviewController
/// 你会发现subviewController的navigationController和viewController的navigationController是同一个
///
func handlePopGestureConflict(with conflictedView: UIScrollView) {
navigationController?
.view
.gestureRecognizers?
.forEach { gesture in
guard gesture is UIScreenEdgePanGestureRecognizer else { return }
conflictedView.panGestureRecognizer.require(toFail: gesture)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment