我正在尝试确定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代码永远不会被解雇。
答案 0 :(得分:0)
将手势识别器添加到PDFView,如下所示:
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTap(_:)))
tapGesture.numberOfTapsRequired = 1
if var recognizer = pdfView.gestureRecognizers {
recognizer.append(tapGesture)
pdfView.gestureRecognizers = recognizer
}