接连显示 UIMenuController 的问题
我正在使用 UIMenuController 的新自定义功能将“复制”以外的内容添加到菜单中,以便剪切并粘贴到 Web 视图中。
我所做的就是获取对共享 UIMenuController 的引用,将 UIMenuItems 的 NSArray 设置到 menuItems 中,只要添加一个项目,一切都可以正常工作。例如我看到[COPY|FOOBAR]。
相反,如果我尝试添加多个项目,会发生什么情况,我会看到 [COPY|MORE],如果我按下 MORE 按钮,最终其他项目就会显示出来。
可以直接显示 [COPY|FOO|BAR|THREE|FOUR] 吗?我看到一些应用程序可以做到这一点,特别是 iBooks。
非常感谢任何帮助,谢谢。
干杯, 西森西奥
I'm using the new customization abilities of the UIMenuController to add things other than "Copy" to the menu for cut&paste into a webview.
What I do is getting the reference to the shared UIMenuController, setting my NSArray of UIMenuItems into the menuItems, and everything work fine as long as I add a single item. For instance I see [COPY|FOOBAR].
Instead if I try adding more than a single item, what happen is that I see [COPY|MORE], if I press into MORE than finally the other items will show up.
Is possible to show directly [COPY|FOO|BAR|THREE|FOUR] instead? I saw a few applications that are able to do this, notably iBooks.
Any help very appreaciated, thank you.
Cheers,
sissensio
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
FluXa的答案实际上是正确的,但我认为它不是很清楚。
问题是,当将自定义 UIMenuItem 对象添加到共享菜单控制器 ([UIMenuController sharedMenuController]) 时,只有第一个自定义 UIMenuItem 将在菜单的初始显示上显示。如果用户点击“更多...”,将显示剩余的自定义菜单项。
但是,如果菜单不包含任何内置系统菜单项(复制:、粘贴:等),则初始菜单显示将显示所有自定义菜单项,并且不显示“更多...”项。< /em>
如果您需要包含内置系统项目,只需添加具有相同标题但具有不同选择器的自定义 UIMenuItems 即可。 ( myCopy: 与 copy: )
本质上它归结为不调用 canPerformAction:withSender: 的默认实现,显式处理所有自定义菜单项,并为所有其他(系统提供的)菜单项返回 NO:
fluXa's answer is actually correct, but I dont think it was very clear.
The issue is that when adding custom UIMenuItem objects to the shared menu controller ([UIMenuController sharedMenuController]), only the first custom UIMenuItem will be shown on the initial display of the menu. The remaining custom menu items will be shown if the user taps "More...".
However, if the menu doesn't include any built-in system menu items (copy:, paste:, etc), the initial menu display will show all custom menu items and no "More..." item.
If you need to include the built-in system items, simply add custom UIMenuItems having the same title but with a different selector. ( myCopy: vs. copy: )
Essentially it boils down to NOT calling the default implementation of canPerformAction:withSender:, explicitly handling all custom menu items, and returning NO for all other (system-supplied) menu items:
当我尝试在 iPad 上开发应用程序时,我们实际上遇到了同样的问题。但我所做的是禁用了弹出菜单项
使用
然后我使用了 UIPopoverController。
问候,
扎尔兹·布兹
we have the same problem actually when i tried to develop an application in iPad. But what i did is i disabled the popup menu items in
Using
Then i used a UIPopoverController.
Regards,
ZaldzBugz
遇到了同样的问题,我所做的就是用子类覆盖 webview(是的,我知道你不应该),并为 copy: 选择器的 canPerformAction: 返回 NO。然后我将自己的 Copy 项目添加到 ShareMenuController 中,该控制器从 UIWebview 调用原始方法。这样,您可以添加任意数量的项目,并且最初都是可见的。
Ran into the same problem and what I did was override the webview with a subclass (yep I know you shouldn't) and return NO for canPerformAction: for the copy: selector. Then I added my own Copy item to the ShareMenuController that calls the original method from UIWebview. That way as many items as you want can be added and are initially visible.
您可以使用 menuFrame (只读属性)获取先前显示的 UIMenuController 的矩形,使用它您可以计算另一个 UIMenuController 在同一位置显示的位置。
在要显示第二个 UIMenuController 的操作方法中,获取前一个 UIMenuController 的框架
大致你会得到箭头的位置。
现在显示第二个 UIMenuController
因为 UIMenuController 是一个单例,如果你想显示以前的 menuItems,再次你必须设置它们。
you can get the rect of the previously displayed UIMenuController using menuFrame (readonly property), using that you can calculate the position for another UIMenuController to be shown at the same place.
In the action method where you are about to show the second UIMenuController, get the frame of the previous UIMenuController
Roughly you will get the arrow position.
Now show the second UIMenuController
since UIMenuController is a singleton, if you want to show the previous menuItems, again you have to set them.