爲分步實施,就可以得到教程here1和here2
class ReaderViewController: UIViewController, UIDocumentInteractionControllerDelegate
func loadDocUsingDocInteractionController() {
if let fileURL = NSBundle.mainBundle().pathForResource("PDFName", ofType: "pdf") { // Use if let to unwrap to fileURL variable if file exists
let docInteractionController = UIDocumentInteractionController(URL: NSURL(fileURLWithPath: fileURL)!)
docInteractionController.delegate = self
docInteractionController.presentPreviewAnimated(true)
}
}
// Return the view controller from which the UIDocumentInteractionController will present itself.
func documentInteractionControllerViewControllerForPreview(controller: UIDocumentInteractionController) -> UIViewController {
return self
}
swift3
class ViewController:UIViewController,UIDocumentInteractionControllerDelegate
,並調用函數像
@IBAction func btnOpenModal(_ sender: UIButton) {
// var button: UIButton? = (sender as? UIButton)
let URLName: URL? = Bundle.main.url(forResource: "sample", withExtension: "pdf")
if URLName != nil {
// Initialize Document Interaction Controller
let documentInteractionController: UIDocumentInteractionController = UIDocumentInteractionController(url: URLName!)
// Configure Document Interaction Controller
documentInteractionController.delegate = self
// Present Open In Menu
documentInteractionController.presentOpenInMenu(from: sender .frame, in: self.view, animated: true)
}
}
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self
}
使用UIDocumentInteractViewController爲您r的概念 –
我找了這個,我沒有找到解決方案。有沒有可以幫助我做的例子或解釋。我正在研究UIPageViewController應用程序,我想添加一個PDF文件,以便所有頁面都顯示在單獨的頁面中。謝謝 –