嗯,你說的是UIDocumentInteractionController那麼。
實施UIDocumentInteractionControllerDelegate在UIViewController
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller { return self; }
- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller { return self.view; }
- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller { return self.view.frame; }
然後添加一個按鈕,導航欄,彈出選項對話框:
// example: opening a .html file
NSString *index = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
// self.controller is a UIDocumentInteractionController ivar
self.controller = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileToOpen]];
self.controller.delegate = self;
CGRect rect = self.navigationController.navigationBar.frame;
rect.size = CGSizeMake(1500.0f, 40.0f); // move the box right down under the button
[self.controller presentOptionsMenuFromRect:rect inView:self.view animated:YES];
支援特定檔案應出現在應用程式的清單。如果您沒有注冊您的應用程式以支援某種類型的文檔,您仍然可以選擇“QuickLook”選項。所有這些都發生在與檔案互動的任何應用程式上(因為檔案本身并未在UI上公開)。