Translate

2014年6月10日 星期二

UIDocumentInteractionController 快速分享到其他應用程式

sample code #import @interface ViewController : UIViewController { IBOutlet UIImageView *img; BOOL preview; UIDocumentInteractionController *documentInteractionController; } @end - (IBAction)shareDocument:(id)sender { NSURL *URL = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"png"]; if (URL) { // Initialize Document Interaction Controller documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL]; if (preview) { [documentInteractionController setDelegate:self]; [documentInteractionController presentPreviewAnimated:YES]; } else { [documentInteractionController presentOpenInMenuFromRect:[sender frame] inView:self.view animated:YES]; } } } #pragma mark - #pragma mark - UIDocumentInteractionControllerDelegate - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller { return self; } - (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller { return self.view; } - (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller { return self.view.frame; }

沒有留言:

張貼留言