我正在尝试确定PDFView上触摸的位置。我将pdf视图设置为可以与用户交互,如下所示:

pdfView?.isUserInteractionEnabled = true

然后,我使用以下功能来检测触摸:
 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    if let touch = touches.first {
        let position = touch.location(in: pdfView)
        print(position)
    }
}

touchesBegan代码从不触发。

最佳答案

如下所示将手势识别器添加到PDFView:

    let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTap(_:)))
    tapGesture.numberOfTapsRequired = 1

     if var recognizer = pdfView.gestureRecognizers {
        recognizer.append(tapGesture)
        pdfView.gestureRecognizers = recognizer
    }

关于ios - touches开始不在PDFView中触发,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46849319/

10-12 19:43