1. 最简单的方法,使用presentPreviewAnimated,如下步骤:
步骤一:
func systemPreview(index :NSInteger) -> Void{ var filePath = fileGroup[index] as String; var fileUrl : NSURL = NSURL(fileURLWithPath: filePath)!; if (docInteractionVC == nil) { docInteractionVC = UIDocumentInteractionController(URL: fileUrl); docInteractionVC!.delegate = self; } docInteractionVC!.URL = fileUrl; var otherCanOpen: Bool = docInteractionVC!.presentPreviewAnimated(true) if !otherCanOpen { println("no support file"); } }
步骤二:实现presentPreviewAnimated的回调,主要是下面的函数
func documentInteractionControllerViewControllerForPreview(controller: UIDocumentInteractionController) -> UIViewController { return self.navigationController!; }2. 还可以使用presentOptionsMenuFromRect:rect、presentOpenInMenuFromRect和回调方法,进行定制。注意,还需要实现上面的回调方法,否则crash。
参考: