Fix conflicting gesture recognizers

This commit is contained in:
Steven Deutsch
2017-08-24 06:11:48 -05:00
parent 4fcbb998c4
commit aaa70b8dad
2 changed files with 10 additions and 6 deletions
+1
View File
@@ -204,6 +204,7 @@ open class MessageCollectionViewCell: UICollectionViewCell {
let messageTapGesture = UITapGestureRecognizer(target: self, action: #selector(didTapMessage))
messageContainerView.addGestureRecognizer(messageTapGesture)
messageTapGesture.delegate = messageLabel
let topLabelTapGesture = UITapGestureRecognizer(target: self, action: #selector(didTapTopLabel))
cellTopLabel.addGestureRecognizer(topLabelTapGesture)
+9 -6
View File
@@ -193,16 +193,19 @@ open class MessageLabel: UILabel, UIGestureRecognizerDelegate {
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
let touchLocation = touch.location(in: self)
guard let index = stringIndex(at: touchLocation) else { return false }
for (_, ranges) in rangesForDetectors {
for nsRange in ranges {
guard let range = nsRange.toRange() else { return false }
if range.contains(index) { return true }
if let index = stringIndex(at: touchLocation) {
for (_, ranges) in rangesForDetectors {
for nsRange in ranges {
guard let range = nsRange.toRange() else { return false }
if range.contains(index) {
return gestureRecognizer.view == self
}
}
}
}
return false
return gestureRecognizer.view != self
}