我有一个使用UIPageViewController而不是scrollView初始化的pdfView,以带有过渡动画的方式一页一页地导航
pdfView.usePageViewController(true, withViewOptions: nil)
代替
pdfView.displayMode = .singlePage
一切正常,包括捏到缩放功能,但我还需要对doubleTap手势做出反应以放大/缩小,这时pdfView拒绝工作。
private func _initTapGestures() {
// Defining various tap gesture
singleTap = UITapGestureRecognizer(target: self, action: #selector(self.handleSingleTapGesture(gesture: )))
singleTap.numberOfTapsRequired = 1
self.addGestureRecognizer(singleTap)
doubleTap = UITapGestureRecognizer(target: self, action: #selector(self.handleDoubleTapGesture(gesture: )))
doubleTap.numberOfTapsRequired = 2
// Prevent singleTap to be triggered in case of doubleTap
singleTap.require(toFail: doubleTap)
self.addGestureRecognizer(doubleTap)
}
// Handles double tap gesture
@objc func handleDoubleTapGesture(gesture: UITapGestureRecognizer) -> Void {
if !doubleTapZoomed {
// Zoom in at an intermediate level
_doubleTapZoomIn()
} else {
// Reset zoom level
_doubleTapZoomOut()
}
}
private func _doubleTapZoomIn() {
doubleTapZoomed = true
// Save the current maxScale factor
let maxScaleFactorReset = self.maxScaleFactor
// Set a new scale factor for an intermediate zoom in
self.maxScaleFactor = 2.5
while self.canZoomIn() {
self.zoomIn(self)
}
// Reset max scale factor to let the user to zoom in even more
self.maxScaleFactor = maxScaleFactorReset
}
private func _doubleTapZoomOut() {
doubleTapZoomed = false
while self.canZoomOut() {
self.zoomOut(self)
}
}
当我使用pdfView的默认导航将代码反转回去时,效果很好,我可以通过双击来放大和缩小...
有人遇到过同样的问题吗?这是PDFKit错误吗?
谢谢。