UITapGestureRecognizer在ios13.1中的PDFView上没有响应

时间:2019-10-22 10:14:04

标签: swift ios13

在PDFView选择器方法上添加UITapGestureRecognizer时,iOS 13+设备中未调用此方法,但在以下OS版本中运行良好。

let barHideOnTapGestureRecognizer = UITapGestureRecognizer()
barHideOnTapGestureRecognizer.addTarget(self, action: #selector(gestureRecognizedToggleVisibility(_:)))
        pdfview.addGestureRecognizer(barHideOnTapGestureRecognizer)

@objc func gestureRecognizedToggleVisibility(_ gestureRecognizer: UITapGestureRecognizer) {
        if navigationController != nil {
            if !bottomView.isHidden {
                hideBars()
            } else {
                showBars()
            }
        }
    }

3 个答案:

答案 0 :(得分:1)

有同样的问题。苹果为PDFView添加了一些自己的手势。我可以通过以下方法解决:

    let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTapped(_:)))
    tapGesture.numberOfTapsRequired = 1
    tapGesture.delegate = pdfView
    if let gestures = pdfView.gestureRecognizers{

        for gesture in gestures {

            if let gesture = gesture as? UITapGestureRecognizer, gesture.numberOfTapsRequired == 1{
            tapGesture.require(toFail: gesture)
            }
        }
    }

    pdfView.addGestureRecognizer(tapGesture)

我还为PDFView创建了它的子类,并设置了以下UIGestureRecognizerDelegate方法:

class DKPDFView : PDFView {

    override func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {

        return true
    }
}

答案 1 :(得分:0)

view.isUserInteractionEnabled = true

您添加了这一行吗?

答案 2 :(得分:0)

这似乎已针对iOS 13.2.2修复