gpt4 book ai didi

ios - Swift PDFKit 分页无法正常工作

转载 作者:行者123 更新时间:2023-11-30 11:48:38 26 4
gpt4 key购买 nike

我正在使用 ios11 中的新 PDFKit 开发 PDF 查看器。我有一份长达 90 页的 pdf 文档作为我的测试文档。重新加载、查看、滚动和导航文档时一切似乎都工作正常。我向导航栏添加了一个分段控件,其中包含 2 个分段,用户可以点击这些分段将 pdfView 显示模式从 singlePageContinously 切换为twoUpContinously,并且它本身也可以正常工作。当 pdf 加载时,就会出现问题,然后我在 pdfView 上捏合缩放,然后点击segmentedControl 更改显示模式...组合捏合缩小,然后点击segmentedControl 更改为说twoUpContinously 使 pdfView 失去对文档中页面的跟踪,最终显示最后几页,即文档的第 87、88、89 和 90 页。再次点击segmentedControl返回singlePageContinously结果我仍然在文档的末尾。

我尝试在滚动时在页面更改上设置 PDFView 观察者,将该页面保存到本地变量,然后调用 pdfView.go(to: currentVisiblePage) 等来尝试规避此问题,但不知何故 pdfView 失去了对正确页面的跟踪,因为分段控件被点击。

我的一些代码

    private func createPDFView() {

// Configure pdfView
pdfView = PDFView()
pdfView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(pdfView)

// Position the pdf view
pdfView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
pdfView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
pdfView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
pdfView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true

// Configure the toolView (created in storyboard)
view.bringSubview(toFront: toolView)
pdfThumbnailView.backgroundColor = Constants.Colors.collectionViewBackground
view.bringSubview(toFront: pdfThumbnailView)



private func addPageObserver() {

//Wednesday, 31 January 2018 trying to get the page number from the notifciation but not easy
pageObserver = NotificationCenter.default.addObserver(forName: Notification.Name.PDFViewPageChanged, object: nil, queue: OperationQueue.main) { [weak self] (notification) in

print("In pageObserver - currentVisiblePage is : \(String(describing: self?.pdfView.currentPage))")
self?.currentVisiblePage = self?.pdfView.currentPage

}
}


@IBAction func segmentedControlTapped(_ sender: UISegmentedControl) {

// Handle 2 or 4 button displayMode segmented control
switch sender.numberOfSegments {

case 2:
// 2 button case
switch sender.selectedSegmentIndex {
case 0:
pdfView.displayMode = .singlePageContinuous
case 1:
pdfView.displayMode = .twoUpContinuous
default:
pdfView.displayMode = .singlePageContinuous
}


default:
break
}

// Re-layout the document to re-centre if document zoomed by pinch before changing displayMode
pdfView.layoutDocumentView()

//
// Get current page from local var and set to try and fix pagination error
if let currentVisiblePage = currentVisiblePage {
print("in seg control handler ... goint to page: \(String(describing: currentVisiblePage))")
pdfView.go(to: currentVisiblePage)
}

}

我再说一遍,如果在更改显示模式之前没有完成缩放,则完全没有问题。感谢任何帮助或指示

最佳答案

如果 scaleFactor 不是 1.0,则似乎 PDFView 中会抛出分页。如果您将页面缩放为 0.5,则尝试更改 pageDisplay 或尝试使用 PDFKit 便捷方法导航到下一页似乎会给出不正确的结果,即将您带到文档中的不正确页面。在进行任何页面操作之前,我必须将scaleFactor重置为1.0才能使其正常工作。

关于ios - Swift PDFKit 分页无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48552158/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com