mirror of
https://github.com/Finb/Bark.git
synced 2025-12-08 21:36:01 +00:00
解决UITextView linkTap 和 单击手势冲突的问题。
This commit is contained in:
parent
64a66b16b8
commit
ca6dcd2be3
@ -15,6 +15,8 @@ class CustomTapTextView: UITextView, UIGestureRecognizerDelegate {
|
||||
private lazy var tapGesture = UITapGestureRecognizer(target: self, action: #selector(tap))
|
||||
/// 双击手势,只是为了让 tapGesture 不要在双击选中文本时触发,没有其他作用
|
||||
private let doubleTapGesture = UITapGestureRecognizer()
|
||||
/// UITextView 自带的点击链接手势
|
||||
private var linkTapGesture: UIGestureRecognizer? = nil
|
||||
|
||||
/// 额外的单击事件
|
||||
var customTapAction: (() -> Void)?
|
||||
@ -30,9 +32,10 @@ class CustomTapTextView: UITextView, UIGestureRecognizerDelegate {
|
||||
self.textContainer.lineFragmentPadding = 0
|
||||
|
||||
tapGesture.delegate = self
|
||||
tapGesture.require(toFail: doubleTapGesture)
|
||||
self.addGestureRecognizer(tapGesture)
|
||||
|
||||
self.linkTapGesture = self.gestureRecognizers?.first { $0 is UITapGestureRecognizer && $0.name == "UITextInteractionNameLinkTap" }
|
||||
|
||||
doubleTapGesture.numberOfTapsRequired = 2
|
||||
doubleTapGesture.delegate = self
|
||||
self.addGestureRecognizer(doubleTapGesture)
|
||||
@ -62,4 +65,16 @@ class CustomTapTextView: UITextView, UIGestureRecognizerDelegate {
|
||||
}
|
||||
return super.gestureRecognizerShouldBegin(gestureRecognizer)
|
||||
}
|
||||
|
||||
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool {
|
||||
if gestureRecognizer == tapGesture {
|
||||
if otherGestureRecognizer == doubleTapGesture {
|
||||
return true
|
||||
}
|
||||
if otherGestureRecognizer == linkTapGesture {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user