0

我有一个 UIToolbar 添加到视图中,并且工具栏有几个 UIBarButtonItem。其中一个按钮将调出 UIDocumentInteractionController Open In 菜单。在 iPhone 中,Open In 菜单的工作方式类似于 UIActionSheet,它将从屏幕底部显示并禁用除自身之外的所有其他按钮(屏幕的其他部分将被浅灰色阴影遮盖,你知道我的意思) .

我的问题是,当 Open In 菜单出现时,UIToolBar 中的所有按钮都消失了,有点像 iOS 的“自动隐藏”。关闭“打开方式”菜单后,按钮将返回。我想要的只是在打开“打开方式”菜单时保持按钮可见。

这个问题只出现在 iOS6(当然还有 iPhone)中,因为在 iOS5 中,Open In 菜单有不同的风格。我不太确定这种行为是否可以改变。然而,Adobe PDF 阅读器应用程序似乎在做和我一样的事情,但工具栏项目永远不会消失。

我用来调出 Open In 菜单的代码是这样的:

[documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.topBar animated:YES]

self.topBar 是我之前提到的工具栏,我也尝试过 self.view、self.view.window 等,但都没有奏效。

我错过了什么吗?还是有一些解决方法?

根据需要添加更多代码:

在 XIB 文件中添加了 UIToolbar,我使用 UIButton 自定义了一个 UIBarbuttonItem,如下所示:

UIButton *button = [UIButton  buttonWithType:UIButtonTypeCustom];
[button setImage:image forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, image.size.width, image.size.height);
[button addTarget:self action:@selector(doSth) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *tItem = [[UIBarButtonItem alloc] initWithCustomView:button];

然后我将 tItem 添加到 UIToolbar 的 items 数组中:

NSArray *items = [NSArray arrayWithObject:tItem];
topBar.items = items;

“doSth”方法只做一件事,只需初始化一个 UIDocumentInteractionController 并显示 Open In 菜单:

UIDocumentInteractionController documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
[documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.topBar animated:YES];

当然,工具栏中还有更多条形按钮项。因此,当显示“打开方式”菜单时,所有按钮都被“隐藏”了。我认为Apple可能会通过设计来做到这一点,但我想知道是否有一些解决方法可以改变这种行为。

4

1 回答 1

0

这里的秘诀是使用 UINavigationBar 而不是 UIToolbar。官方应该在屏幕底部使用 UIToolbars,在顶部使用 UINavigationBars。(然而,这在以前可能是不可能的,因为直到 iOS5,UINavigationBar 才可以在每一端有多个项目。)

这似乎是 Apple 的“设计”。有关此功能可能有用的示例,请在查看 Dropbox 应用中的文件时查看底部工具栏。(如果他们不隐藏项目,他们将直接降落在“取消”按钮的接缝处。)

于 2013-03-15T00:10:16.217 回答