![]() The full solution is available in this gist. That said, it works for now and I'm happy with the solution. To enable this, find the PDFScrollView in your PDFView and: tValue(true, forKey: "forcesTopAlignment")Īfter a few days up against the wall I finally figured out a way to get PDFView to behave how I want.ĭisclosure: This solution uses method swizzling and relies on private view hierarchy and could break at any time. So it turns out, after digging through some more private APIs (yes, this solution is still gross) that there is this magical property that I had completely overlooked on PDFScrollView (a private, internal view) called. Creating my own page controller and render a single PDF page per page (not using ePageViewController)ĭoes anyone have any ideas of how I can achieve what I'm after?.Intercepting the pinch gesture and adjusting the document view's center.Adjusting the transform on the document view.PDFViewVisiblePagesChanged which does fire as the next/previous pages are coming into view (as well as a few more times, which is fine) and this has the same issue as with. PDFViewPageChanged notification only fires after the scroll view ends decelerating, so the page is zoomed out as it's scrolling in and then when I adjust the scale factor it jumps to fit the width of the screen. To attempt to solve the "tall page problem" () I've tried adjusting the scale factor of the PDFView whenever a new page appears. This approach, aside from relying on private view hierarchy, just won't work. However, once the user pinches to zoom on that page, its frame is automatically jumps back to being centered. This works in that whenever the next or previous page is scrolling into view, the page is rendered at the top of the view. First, and this is gross and I know it's wrong, after inspecting the view hierarchy and finding the private view (a view of class named PDFTextInputView) that the page is rendered within I've tried adjusting its frame's origin.y to 0 whenever the outer-most scrollview (another private view) scrolls. To attempt to solve the first issue, the vertical offset, I have attempted several things. Each page is centered vertically in the PDFView, and if its height of the page is greater than the height of the view (e.g. This is due to the varying heights of the pages. ePageViewController(true, withViewOptions: nil) I would like to use PDFKit's PDFView, especially since these settings can be achieved by: let pdfView = PDFView() I have a PDF that has pages of different heights that I want to display in a horizontally paged fashion, one page at a time, with no gaps between pages, and the top of each page being aligned with the top of the view. Let's now figure out how to open it using PDFView, embedded in PDFKit - Apple's convenient framework available from iOS 11.Īlthough many PDFKit tutorials use storyboard to create PDFView using the UIView property, this cannot be done through Xibs. So, we have moved the PDF file, and now the user has access to it. Print( "Copy Error: \(error.localizedDescription)") Let destinationURL = documentsPath.appendingPathComponent(url.lastPathComponent) Import UIKit class ViewController: UIViewController It is also necessary to track where our files have moved, so the observer, which in my case is a ViewController, must support URLSessionDownloadDelegate. To download a file via a URL, you need to use downloadTask. For this task, you need to perform 3 steps: I am working on an application that should be able to download PDF files, save them and open them. ![]() Good afternoon, I present to your attention the translation of the article on the work of PDF in Swift.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |