Reputation: 326
I am working in pdf editing project, in that I have to add signature in pdfview and after that need to resize and delete that signature. Now for this I am adding one scrollview with UIView on top of pdfview with transparent alpha and add image view to that UIView but I had an issue with zooming. How can I get how much zoom pdfview zooming when user pinch zoom. I want to find pdfview's zoom contentInset, so I can set my own scrollview's contentInset.
try to get pdfview scale factor when pdfview zoom with :
@objc func pdfViewScaleChange(notification:NSNotification){
print(self.pdfView.scaleFactor)
}
But Still I can't find How can I zoom and set my UIScrollview as pdfview zoom.
Upvotes: 3
Views: 1511
Reputation: 101
Your PDFView has a property called scaleFactorForSizeToFit
, which is the scale factor that PDFKits autoScales
would use for scaling the current document and layout.
What this means is that if you use the autoScales
property when you set your pdf you will be able to calculate an amount to scale your UIScrollview by.
Here is an example of what I mean for some more context:
//wherever you set your pdf (doesn't have to be viewDidAppear)
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
pdfView.document = PDFDocument(data: data)
pdfView.autoScales = true
//Add the observer here to detect when your pdf is zoomed in or out
NotificationCenter.default.addObserver(self,
selector: #selector(pdfPageWasZoomed),
name: Notification.Name.PDFViewPageChanged,
object: nil)
}
//wherever you want to zoom use this
func getScrollViewScaleFactor() -> CGFloat {
return (pdfView.scaleFactor / pdfView.scaleFactorForSizeToFit)
}
//Objc function which is called everytime the zoom changes
@objc private func pdfPageWasZoomed() {
//Here use the function getScrollViewScaleFactor() to get a factor to scale in or out by
}
Something like this should solve your problem.
Upvotes: 2