From aaa70b8dade16a753429ae54838c688ef8b6cbc2 Mon Sep 17 00:00:00 2001 From: Steven Deutsch Date: Thu, 24 Aug 2017 06:11:48 -0500 Subject: [PATCH] Fix conflicting gesture recognizers --- Sources/MessageCollectionViewCell.swift | 1 + Sources/MessageLabel.swift | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Sources/MessageCollectionViewCell.swift b/Sources/MessageCollectionViewCell.swift index f2307b44..5bf2bff5 100644 --- a/Sources/MessageCollectionViewCell.swift +++ b/Sources/MessageCollectionViewCell.swift @@ -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) diff --git a/Sources/MessageLabel.swift b/Sources/MessageLabel.swift index 500f2ac5..ca4fbeee 100644 --- a/Sources/MessageLabel.swift +++ b/Sources/MessageLabel.swift @@ -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 }