为分步实施,就可以得到教程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文件,以便所有页面都显示在单独的页面中。谢谢 –