Last active
June 14, 2019 10:49
-
-
Save guzhenhuaGitHub/6f571013f1656eb0e33748fcf898a3ad to your computer and use it in GitHub Desktop.
解决scrollView右滑与系统右滑返回上级页面手势冲突
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 解决视图右滑与系统右滑返回上级页面手势冲突 | |
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