Prioritize the double-tap-to-zoom gesture over other double-tap gestures

This commit is contained in:
Jed Fox 2023-07-04 08:49:55 -04:00
parent e16185fa71
commit 967b7e5b53
No known key found for this signature in database
GPG Key ID: 0B61D18EA54B47E1
1 changed files with 17 additions and 0 deletions

View File

@ -70,6 +70,8 @@ extension MediaPreviewImageView {
addSubview(imageView)
doubleTapGestureRecognizer.addTarget(self, action: #selector(MediaPreviewImageView.doubleTapGestureRecognizerHandler(_:)))
doubleTapGestureRecognizer.delegate = self
imageView.addGestureRecognizer(doubleTapGestureRecognizer)
if #available(iOS 16.0, *) {
imageView.addInteraction(liveTextInteraction)
@ -113,6 +115,21 @@ extension MediaPreviewImageView {
}
extension MediaPreviewImageView: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool {
guard gestureRecognizer == doubleTapGestureRecognizer else { return false }
// block double-tap to select text gesture
// but only if the Live Text button is toggled off
if let gr = otherGestureRecognizer as? UITapGestureRecognizer,
gr.numberOfTapsRequired == 2,
#available(iOS 16, *),
!liveTextInteraction.selectableItemsHighlighted {
return true
}
return false
}
}
extension MediaPreviewImageView {
func setup(image: UIImage, container: UIView, forceUpdate: Bool = false) {