UIDocumentInteractionController 将自定义操作添加到菜单(例如电子邮件、保存到照片)

发布于 2024-10-20 14:28:32 字数 231 浏览 2 评论 0原文

我已经开始在新应用程序中使用 UIDocumentInteractionController,但我想知道如何向预览屏幕上显示的操作菜单添加其他操作?

菜单似乎只列出了已注册给定 url 类型的应用程序,而且我看到 iOS4.2 上显示了 PRINT。我想添加通过电子邮件发送并保存到照片,但没有看到扩展此菜单的方法。我可以编写我想要的操作,好吧,只是将它们添加到菜单中,这似乎是不可能的?

我错过了一些明显的东西吗?

I've started using UIDocumentInteractionController for a new app but I'm wondering how to add additional actions to the action menu that you get on the preview screen?

It seems that the menu only lists apps that have registered for a given url type plus I'm seeing PRINT showing up on iOS4.2. I would like to add send by email and save to photos but don't see a way of extending this menu. I can code the actions I want OK, it's just adding them into the menu that seems impossible?

Am I missing something obvious?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

如若梦似彩虹 2024-10-27 14:28:32

你是对的,
这些是方法

- (BOOL) documentInteractionController: (UIDocumentInteractionController *) controller performAction: (SEL) action


- (BOOL) documentInteractionController: (UIDocumentInteractionController *) controller canPerformAction: (SEL) action

这些方法支持的操作选择器是 copy:print:

You are correct,
These are the methods

- (BOOL) documentInteractionController: (UIDocumentInteractionController *) controller performAction: (SEL) action


- (BOOL) documentInteractionController: (UIDocumentInteractionController *) controller canPerformAction: (SEL) action

The supported action selectors for these methods are copy: and print:.

如梦初醒的夏天 2024-10-27 14:28:32

我还不能发表评论,所以我来回答:-)

你应该尝试一下 QuickLook 框架。就我而言,我搜索了所有如何自定义 UIDocumentInteractionController 的方法,但没有找到任何有用的东西。我使用 QuickLook 实现了我想要的目标(在我的例子中,在另一个视图中具有预览“视图”)。这是一个示例代码,将 QLPreviewController 作为子控制器(能够自由创建父控制器,这将在您的情况下完成任务)。

self.previewController = [[QLPreviewController alloc]init];
self.previewController.delegate=self;
self.previewController.dataSource=self;
[self addChildViewController:self.previewController];
self.previewController.view.frame = CGRectMake(0, 0, self.previewView.frame.size.width, self.previewView.frame.size.height);
[self.previewView addSubview:self.previewController.view];
[self.previewController didMoveToParentViewController:self];

您还需要一些委托:QLPreviewControllerDataSource 和 QLPreviewControllerDelegate

,还需要实现一些委托:

- (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index

将 NSURL 返回到资源

- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller

,返回要预览的项目数(在我的例子中为 1)

I cannot comment yet so I'm answering instead :-)

You should give QuickLook framework a try. In my case, I searched all over how to customize UIDocumentInteractionController and failed to find anything useful. I achieved what I wanted (in my case, having a preview "view" inside another view) using QuickLook. Here's a sample code, to have a QLPreviewController as a child controller (being able to create the parent controller freely, which will do the trick in your case).

self.previewController = [[QLPreviewController alloc]init];
self.previewController.delegate=self;
self.previewController.dataSource=self;
[self addChildViewController:self.previewController];
self.previewController.view.frame = CGRectMake(0, 0, self.previewView.frame.size.width, self.previewView.frame.size.height);
[self.previewView addSubview:self.previewController.view];
[self.previewController didMoveToParentViewController:self];

You will also need some delegates: QLPreviewControllerDataSource and QLPreviewControllerDelegate

and also some need to implement:

- (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index

return NSURL to the resource

- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller

return the number of items to preview (in my case, 1)

最笨的告白 2024-10-27 14:28:32

要显示电子邮件和“保存到”选项,您应该使用

- (BOOL)presentOptionsMenuFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated;

- (BOOL)presentOptionsMenuFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated;

如 UIDocumentInteractionController.h 中所述:

/ 这是您应该调用的默认方法,以便您的用户可以选择快速查看、打开或复制文档。
/

使用时

// 显示一个菜单,允许用户在另一个应用程序中打开文档。

- (BOOL)presentOpenInMenuFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated;

- (BOOL)presentOpenInMenuFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated;

不显示电子邮件、短信和“保存在照片/视频中”。

如果需要其他无法识别的操作,请考虑使用 UIActionSheet。

To display email and 'save to' options you should use

- (BOOL)presentOptionsMenuFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated;

or

- (BOOL)presentOptionsMenuFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated;

As described in UIDocumentInteractionController.h :

/ This is the default method you should call to give your users the option to quick look, open, or copy the document.
/

While using

// Presents a menu allowing the user to open the document in another application.

- (BOOL)presentOpenInMenuFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated;

or

- (BOOL)presentOpenInMenuFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated;

email, sms and 'save in photo/video' are not displayed.

If other actions are required that are not recognized, consider using UIActionSheet.

鸩远一方 2024-10-27 14:28:32

如果您在 iPad 上使用带有应用程序的表格视图,并且可以手动添加打印、电子邮件和其他所有内容,我可以建议您使用简单的 UIActionSheet 或更好的弹出窗口。

i could suggest a simple UIActionSheet or better a popover if you are on iPad with inside a table view with apps and you can manually add Print,email and everything else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文