'How to do a double tap zoom in using PDFView's built in PageViewController?
I'm building a pdf viewer using PDFKit and the built in page view controller that's in PDFView. I want to be able to double tap the page and zoom in on that part of the screen.
I've tried the zoomIn: method and that doesn't seem to work with the page controller. I've also tried creating a PDFDestination and then using go(to:) on the PDFView but it isn't zooming in. I've also tried going to the destination and then just changing the scale factor but that just zooms in on the center of the page.
Here is my tap gesture:
doubleScreenTap = UITapGestureRecognizer(target: self, action: #selector(zoomIn(_:)))
doubleScreenTap.numberOfTapsRequired = 2
doubleScreenTap.numberOfTouchesRequired = 1
containerView.addGestureRecognizer(doubleScreenTap)
Here is the function that is being called:
@IBAction func zoomIn(_ gestureRecognizer: UITapGestureRecognizer)
{
if gestureRecognizer.state == .ended
{
if let currentPage = pdfView.currentPage
{
let point = gestureRecognizer.location(in: pdfView)
let destination = PDFDestination(page: currentPage, at: point)
destination.zoom = (pdfView.scaleFactor * 1.5)
pdfView.go(to: destination)
{
{
}
I looking to be able to zoom in on spot that is tapped. Let me know if I'm doing anything wrong or any knowledge you have on this. Thanks
Solution 1:[1]
If I am not mistaken this feature is already available for PDFView. It will work if you will define scale factor
pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit
pdfView.maxScaleFactor = 4.0
pdfView.scaleFactor = pdfView.scaleFactorForSizeToFit
Solution 2:[2]
// this enable double tap to zoom
pdfView.enableDataDetectors = false;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dmitry Kuleshov |
| Solution 2 | lcyper |
